Function better_any::nightly::downcast_tid
source · [−]pub fn downcast_tid<'a, From: IntoRawPtr, To: IntoRawPtr<Lifetime = From::Lifetime>>(
f: From
) -> Result<To, From>where
From::Pointee: Pointee + DynMetadataType,
To::Pointee: Sized,
*const To::Pointee: CoerceUnsized<*const From::Pointee>,
<From::Pointee as DynMetadataType>::Over: Tid<'a>,
Expand description
Downcasts any kind of fat pointer type which vtable corresponds to a trait with Tid
bound.
For example Rc<RefCell<dyn Tid<'_>>>>
can be downcasted with this method
struct Test(i32);
tid!(Test);
let a = Box::new(Test(5i32));
let any = a as Box<dyn Tid>;
let result: Box<Test> = downcast_tid(any).unwrap_or_else(|_| panic!("error"));
assert_eq!(5, result.0);