[][src]Trait safecast::TryCastInto

pub trait TryCastInto<T>: Sized {
    pub fn can_cast_into(&self) -> bool;
pub fn opt_cast_into(self) -> Option<T>; pub fn try_cast_into<Err, OnErr: FnOnce(&Self) -> Err>(
        self,
        on_err: OnErr
    ) -> Result<T, Err> { ... } }

Trait for defining a cast operation when the destination type cannot always be cast from the source type. Defines a can_cast_into method which borrows self, allowing for pattern matching without moving self. If can_cast_into returns true, then calling opt_cast_into must return Some(...), otherwise try_cast_into may panic.

Analogous to TryFrom. The inverse of TryCastInto. Prefer implementing TryCastFrom over TryCastInto because implementing TryCastFrom automatically provides an implementation of TryCastInto.

Required methods

pub fn can_cast_into(&self) -> bool[src]

Test if self can be cast into T.

pub fn opt_cast_into(self) -> Option<T>[src]

Returns Some(T) if self can be cast into T, otherwise None.

Loading content...

Provided methods

pub fn try_cast_into<Err, OnErr: FnOnce(&Self) -> Err>(
    self,
    on_err: OnErr
) -> Result<T, Err>
[src]

Returns Ok(T) if self can be cast into T, otherwise calls on_err.

Loading content...

Implementors

impl<F, T: TryCastFrom<F>> TryCastInto<T> for F[src]

Loading content...