pub trait Cast<T> {
type Error: Into<Error> + Error;
// Required methods
fn try_cast(self) -> Result<T, Self::Error>;
fn cast(self) -> T;
}Expand description
This trait has similarities to Into and TryInto, but limited to
numeric conversions:
- Conversions may be fallible, like
TryInto. - Conversions must be lossless, like
Into; this corresponds to theExact“rounding” mode. (See alsoCastApprox.) - Conversions must be value-preserving, like
Into. For example,-1_i8and-1_i32are conceptually the same value while255_u8is conceptually a different value.
This trait is automatically implemented for every implementation of
Conv.
Required Associated Types§
Sourcetype Error: Into<Error> + Error
type Error: Into<Error> + Error
Conversion error type
This should be one of Infallible, RangeError or Error.
Required Methods§
Sourcefn cast(self) -> T
fn cast(self) -> T
Cast from Self to T
Use this method only when success is expected. On error, this method may panic or may exhibit § Fallback behaviour.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".