Not automatically, you will need to implement methods on traits like this,
pub trait FrpNodeAny {
fn update(&self);
fn parents(&self) -> Vec<Rc<dyn FrpNodeAny>>;
fn into_rc_any(self: Rc<Self>) -> Rc<FrpNodeAny>;
}
But this is burdensome on the user, the solution to this problem is yet another trait
pub trait IntoFrpNodeAny {
fn into_rc_any(self: Rc<Self>) -> Rc<FrpNodeAny>;
fn as_any(&self) -> &FrpNodeAny;
fn as_any_mut(&mut self) -> &mut FrpNodeAny;
// add methods for whatever pointer like type here
}
pub trait FrpNodeAny: IntoFrpNodeAny {
fn update(&self);
fn parents(&self) -> Vec<Rc<dyn FrpNodeAny>>;
}
// this is important, you can't move this implementation into the trait
// as default methods, because these coercions require `Sized` bounds
// which are provided here, but can't in the trait
impl<T: FrpNodeAny> IntoFrpNodeAny for T {
fn into_rc_any(self: Rc<Self>) -> Rc<FrpNodeAny> { self }
fn as_any(&self) -> &FrpNodeAny { self }
fn as_any_mut(&mut self) -> &mut FrpNodeAny { self }
}
This way implementors of FrpNodeAny
don't need to think about it, they just get it for free.
you can then use this like so,
pub fn magic<Out>(x: Rc<dyn FrpNode<Out>>) -> Rc<dyn FrpNodeAny> {
x.into_rc_any()
}