Storing a trait as a member in a struct

⚓ Rust    📅 2025-11-20    👤 surdeus    👁️ 8      

surdeus

Hello,

I would like how to store a trait member in a struct the most idiomatic / best way.

I suppose Box<dyn Trait + 'static> is one way of doing it. But 'static doesn't seem, unless proven wrong, to be the best way of doing / writing it. Is there another way ?

Unfortunately, there doesn't seem to be a lot of resources on the net concerning this specific subject.

Hoping I was clear enough, thank you very much in advance for any help.

7 posts - 4 participants

Read full topic

🏷️ Rust_feed