az

Trait CastFrom

Source
pub trait CastFrom<Src> {
    // Required method
    fn cast_from(src: Src) -> Self;
}
Expand description

Used to cast values.

This trait enables trait constraints for casting in the opposite direction to Cast.

§Examples

use az::CastFrom;
trait Tr {
    type Assoc: CastFrom<u8>;
    fn assoc_from_u8(a: u8) -> Self::Assoc {
        CastFrom::cast_from(a)
    }
}
impl Tr for () {
    type Assoc = i8;
}
assert_eq!(<() as Tr>::assoc_from_u8(5u8), 5i8);

Required Methods§

Source

fn cast_from(src: Src) -> Self

Casts the value.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<Src: Cast<Dst>, Dst> CastFrom<Src> for Dst