[][src]Struct traitcast_core::Registry

pub struct Registry {
    pub tables: Map<dyn Any + Sync>,
}

A registry defining how to cast into some set of traits.

Fields

tables: Map<dyn Any + Sync>

Methods

impl Registry[src]

pub fn new() -> Registry[src]

Makes a new, empty trait registry.

pub fn insert<DynTrait: ?Sized + 'static>(
    &mut self,
    table: CastIntoTrait<DynTrait>
)
[src]

Updates the table defining how to cast into the given trait.

pub fn cast_into<To: ?Sized>(&self) -> Option<&CastIntoTrait<To>> where
    To: 'static, 
[src]

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 !Send for Registry

impl Sync for Registry

Blanket Implementations

impl<T> TraitcastFrom for T where
    T: 'static, 
[src]

fn type_id(&self) -> TypeId[src]

Get the trait object's dynamic type id.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Any for T where
    T: Any
[src]