Return &[&dyn Trait] from member Vec>
⚓ Rust 📅 2025-05-16 👤 surdeus 👁️ 10I have a struct similar to this:
struct MyStruct {
things: Vec<Box<dyn MyTrait>>
}
And I'd like to be able to do this:
fn get_all_things(&self) -> &[&dyn MyTrait] {
how?
}
i.e. I'd like to return a slice of references to something that implements the trait rather than &[Box<dyn MyTrait>].
Is it possible?
7 posts - 5 participants
🏷️ rust_feed