Trait moonshine_kind::CastInto

source ·
pub trait CastInto<T: Kind>: Kind {
    // Required method
    fn cast_into(instance: Instance<Self>) -> Instance<T>;
}
Expand description

A trait which allows safe casting from one Kind to another.

§Usage

It is recommended to use the safe_cast macro to implement this trait.

§Example

The expression safe_cast!(Apple => Fruit) is equivalent to:


impl CastInto<Fruit> for Apple {
    fn cast_into(instance: Instance<Apple>) -> Instance<Fruit> {
        unsafe { instance.cast_into_unchecked() }
    }
}

Required Methods§

source

fn cast_into(instance: Instance<Self>) -> Instance<T>

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T: Kind> CastInto<Any> for T