Downcasting a value stored in HashMap and returning Option<&T>
⚓ Rust 📅 2025-05-03 👤 surdeus 👁️ 9Hi all, I would really appreciate it if someone could take a look at the code below and tell me why the code doesn't work? Also what can I do to get this to work.
Short summary of what I am trying to achieve:
- I have a trait for example
SomeTrait - I have a struct
Barwhich contains a fielddatawhich is HashMap<String, Box>
I am writing a method get<T> for Bar which should access the stored value and return Option<&T>
Following is the example code I have:
EDIT: Fixed the link
So my question is if there is an ideal way to fix this? Preferably by not creating a new owned value?
7 posts - 5 participants
🏷️ rust_feed