pub trait TidExt<'a>: Tid<'a> {
// Provided methods
fn is<T>(&self) -> bool
where T: Tid<'a> { ... }
fn downcast_ref<'b, T>(&'b self) -> Option<&'b T>
where T: Tid<'a> { ... }
fn downcast_mut<'b, T>(&'b mut self) -> Option<&'b mut T>
where T: Tid<'a> { ... }
fn downcast_rc<T>(self: Rc<Self>) -> Result<Rc<T>, Rc<Self>>
where T: Tid<'a> { ... }
fn downcast_arc<T>(self: Arc<Self>) -> Result<Arc<T>, Arc<Self>>
where T: Tid<'a> { ... }
fn downcast_box<T>(self: Box<Self>) -> Result<Box<T>, Box<Self>>
where T: Tid<'a> { ... }
fn downcast_move<T>(self) -> Option<T>
where T: Tid<'a>,
Self: Sized { ... }
}Expand description
Re-export public API. Extension trait that contains actual downcasting methods.
Use methods from this trait only if dyn Tid was created directly from T for this particular T
If Self is Sized then any of those calls is optimized to no-op because both T and Self are known statically.
Useful if you have generic code that you want to behave differently depending on which
concrete type replaces type parameter. Usually there are better ways to do this like specialization,
but sometimes it can be the only way.
Provided Methods§
Sourcefn is<T>(&self) -> boolwhere
T: Tid<'a>,
fn is<T>(&self) -> boolwhere
T: Tid<'a>,
Returns true if type behind self is equal to the type of T.
Sourcefn downcast_ref<'b, T>(&'b self) -> Option<&'b T>where
T: Tid<'a>,
fn downcast_ref<'b, T>(&'b self) -> Option<&'b T>where
T: Tid<'a>,
Attempts to downcast self to T behind reference
Sourcefn downcast_mut<'b, T>(&'b mut self) -> Option<&'b mut T>where
T: Tid<'a>,
fn downcast_mut<'b, T>(&'b mut self) -> Option<&'b mut T>where
T: Tid<'a>,
Attempts to downcast self to T behind mutable reference
Sourcefn downcast_rc<T>(self: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Tid<'a>,
fn downcast_rc<T>(self: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Tid<'a>,
Attempts to downcast self to T behind Rc pointer
Sourcefn downcast_arc<T>(self: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Tid<'a>,
fn downcast_arc<T>(self: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Tid<'a>,
Attempts to downcast self to T behind Arc pointer
Sourcefn downcast_box<T>(self: Box<Self>) -> Result<Box<T>, Box<Self>>where
T: Tid<'a>,
fn downcast_box<T>(self: Box<Self>) -> Result<Box<T>, Box<Self>>where
T: Tid<'a>,
Attempts to downcast self to T behind Box pointer
Sourcefn downcast_move<T>(self) -> Option<T>
fn downcast_move<T>(self) -> Option<T>
Attempts to downcast owned Self to T,
useful only in generic context as a workaround for specialization
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.