Downcasting y Box <Any>
pub struct WidgetWrap {
// ...
widget: RefCell<Box<Any>>,
}
En algún momento quiero lanzarBox<Any>
aBox<WidgetTrait>
let mut cell = widget.borrow_mut();
let w = cell.downcast_mut::<Box<WidgetTrait>>();
Esto me da un error de este tipo:
error: instantiating a type parameter with an incompatible type
`Box<WidgetTrait>`, which does not fulfill `'static` [E0144]
¿Qué significa esto realmente?
He miradoCómo solucionarlo: el valor puede contener referencias; agregue '' static` vinculado a `T` e intenté agregar+ 'static
en todos lados.
pub struct WidgetWrap {
// ...
widget: RefCell<Box<Any + 'static>>,
}
let mut cell = widget.borrow_mut();
let w = cell.downcast_mut::<Box<WidgetTrait + 'static>>();
Soluciona los errores de compilación, pero falla cuando intento desenvolver el cuadro descargado como se muestra arriba. Y sí, el contenido de la caja es un objeto que implementaWidgetTrait
.
Obviamente, estoy codificando en Rust a un nivel que no entiendo muy bien, pero tal vez alguien pueda ayudarme a comprender mejor los conceptos involucrados en la tarea anterior.