Struct Registry

Source
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

Source

pub fn new() -> Registry

Makes a new, empty trait registry.

Source

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

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

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> TraitcastFrom for T
where T: 'static,

Source§

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)

Cast to a mutable reference to a trait object.
Source§

fn as_any_box(self: Box<T>) -> Box<dyn Any>

Cast to a boxed reference to a trait object.
Source§

fn type_id(&self) -> TypeId

Get the trait object’s dynamic type id.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Any for T
where T: Any,