pub struct WidgetWrap {
// ...
widget: RefCell<Box<Any>>,
}
At some point I want to cast Box<Any>
to Box<WidgetTrait>
let mut cell = widget.borrow_mut();
let w = cell.downcast_mut::<Box<WidgetTrait>>();
This gives me an error of this kind:
error: instantiating a type parameter with an incompatible type
`Box<WidgetTrait>`, which does not fulfill `'static` [E0144]
What does this really mean?
I've looked at How to fix: value may contain references; add `'static` bound to `T` and did try adding + 'static
everywhere.
pub struct WidgetWrap {
// ...
widget: RefCell<Box<Any + 'static>>,
}
let mut cell = widget.borrow_mut();
let w = cell.downcast_mut::<Box<WidgetTrait + 'static>>();
It fixes the compile errors, but fails when I try to unwrap the downcasted box as shown above. And yes, the content of the box is an object that implements WidgetTrait
.
Obviously, I am coding in Rust at a level that I don't quite understand, but maybe someone can help me get a better grip on the concepts involved in the above task.
Box<Any>
at all if it's supposed to be aBox<WidgetTrait>
? – DrunkenBox<Any>
are a wide variety of values. They all have theWidgetTrait
, but I also need to occasionally cast them to their specific instances. – Unlicensed