[−][src]Trait safecast::TryCastInto
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
.
Provided methods
pub fn try_cast_into<Err, OnErr: FnOnce(&Self) -> Err>(
self,
on_err: OnErr
) -> Result<T, Err>
[src]
self,
on_err: OnErr
) -> Result<T, Err>
Returns Ok(T)
if self
can be cast into T
, otherwise calls on_err
.