[][src]Trait async_ecs::CastFrom

pub unsafe trait CastFrom<T> {
    pub fn cast(t: &T) -> &Self;
pub fn cast_mut(t: &mut T) -> &mut Self; }

Helper trait for the MetaTable. This trait is required to be implemented for a trait to be compatible with the meta table.

Memory safety

Not casting self but e.g. a field to the trait object can result in severe memory safety issues.

Examples

use async_ecs::*;

trait Foo {
    fn foo1(&self);
    fn foo2(&mut self, x: i32) -> i32;
}

unsafe impl<T> CastFrom<T> for dyn Foo
where
    T: Foo + 'static,
{
    fn cast(t: &T) -> &(dyn Foo + 'static) {
        t
    }

    fn cast_mut(t: &mut T) -> &mut (dyn Foo + 'static) {
        t
    }
}

Required methods

pub fn cast(t: &T) -> &Self[src]

Casts an immutable T reference to a trait object.

pub fn cast_mut(t: &mut T) -> &mut Self[src]

Casts a mutable T reference to a trait object.

Loading content...

Implementors

impl<T> CastFrom<T> for dyn AnyStorage where
    T: AnyStorage + 'static, 
[src]

Loading content...