I am having problems downcasting a trait inside a Rc
and a RefCell
. My code reads as follows.
pub trait Eventful
{
// ... some methods
}
#[derive(Clone)]
pub enum Event
{
// ... other events,
Generic(Rc<RefCell<Eventful>>),
}
pub trait Router: Eventful
{
// ... more methods
}
struct Network
{
// ... other fields
routers: Vec<Rc<RefCell<Router>>>,
}
Then with this I get an error[E0308]: mismatched types.
Event::Generic(network.routers[router])
And with this I get an error[E0605]: non-primitive cast.
Event::Generic(network.routers[router] as Rc<RefCell<Eventful>>)
Can I resolve this cast?