Trait Upcast

Source
pub trait Upcast: Sized {
    type Higher;

    // Required methods
    fn upcast(self) -> Self::Higher;
    fn downcast(inp: Self::Higher) -> Option<Self>;
}
Expand description

Performs upcasting to type with higher (and/or lower) limits.

i.e. casts u8 to u16

Required Associated Types§

Source

type Higher

The higher type casted to (if Self is u8, this is u16).

Required Methods§

Source

fn upcast(self) -> Self::Higher

Casts self to higher.

Source

fn downcast(inp: Self::Higher) -> Option<Self>

Attempts to cast down to lower from higher. Returns Option::None if inp exceeds the limits of Self.

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.

Implementations on Foreign Types§

Source§

impl Upcast for i8

Source§

type Higher = i16

Source§

fn upcast(self) -> Self::Higher

Source§

fn downcast(inp: Self::Higher) -> Option<Self>

Source§

impl Upcast for i16

Source§

type Higher = i32

Source§

fn upcast(self) -> Self::Higher

Source§

fn downcast(inp: Self::Higher) -> Option<Self>

Source§

impl Upcast for i32

Source§

type Higher = i64

Source§

fn upcast(self) -> Self::Higher

Source§

fn downcast(inp: Self::Higher) -> Option<Self>

Source§

impl Upcast for i64

Source§

type Higher = i128

Source§

fn upcast(self) -> Self::Higher

Source§

fn downcast(inp: Self::Higher) -> Option<Self>

Source§

impl Upcast for u8

Source§

type Higher = u16

Source§

fn upcast(self) -> Self::Higher

Source§

fn downcast(inp: Self::Higher) -> Option<Self>

Source§

impl Upcast for u16

Source§

type Higher = u32

Source§

fn upcast(self) -> Self::Higher

Source§

fn downcast(inp: Self::Higher) -> Option<Self>

Source§

impl Upcast for u32

Source§

type Higher = u64

Source§

fn upcast(self) -> Self::Higher

Source§

fn downcast(inp: Self::Higher) -> Option<Self>

Source§

impl Upcast for u64

Source§

type Higher = u128

Source§

fn upcast(self) -> Self::Higher

Source§

fn downcast(inp: Self::Higher) -> Option<Self>

Implementors§