pub struct Registry {
pub tables: Map<dyn Any + Sync>,
}
Expand description
A registry defining how to cast into some set of traits.
Fields§
§tables: Map<dyn Any + Sync>
Implementations§
Source§impl Registry
impl Registry
Sourcepub fn insert<DynTrait: ?Sized + 'static>(
&mut self,
table: CastIntoTrait<DynTrait>,
)
pub fn insert<DynTrait: ?Sized + 'static>( &mut self, table: CastIntoTrait<DynTrait>, )
Updates the table defining how to cast into the given trait.
Sourcepub fn cast_into<To>(&self) -> Option<&CastIntoTrait<To>>where
To: ?Sized + 'static,
pub fn cast_into<To>(&self) -> Option<&CastIntoTrait<To>>where
To: ?Sized + 'static,
Gets the table defining how to cast into the given trait.
This method is designed to be chained with from_mut, from_ref or from_box.
§Examples
let x: &dyn Bar = ...;
registry.cast_into::<Foo>()?.from_ref(x)
let x: &mut dyn Bar = ...;
registry.cast_into::<Foo>()?.from_mut(x)
let x: Box<dyn Bar> = ...;
registry.cast_into::<Foo>()?.from_box(x)
Auto Trait Implementations§
impl Freeze for Registry
impl !RefUnwindSafe for Registry
impl !Send for Registry
impl Sync for Registry
impl Unpin for Registry
impl !UnwindSafe for Registry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> TraitcastFrom for Twhere
T: 'static,
impl<T> TraitcastFrom for Twhere
T: 'static,
Source§fn as_any_ref(&self) -> &(dyn Any + 'static)
fn as_any_ref(&self) -> &(dyn Any + 'static)
Cast to an immutable reference to a trait object.
Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Cast to a mutable reference to a trait object.