Trait az::Cast

source · []
pub trait Cast<Dst> {
    fn cast(self) -> Dst;
}
Expand description

Used to cast values.

It is normally easier to use the Az trait instead of this trait.

Panics

When debug assertions are enabled, this trait’s method panics if the value does not fit in the destination. When debug assertions are not enabled (usual in release mode), the wrapped value can be returned, but it is not considered a breaking change if in the future it panics; if wrapping is required use WrappingCast instead.

This trait’s method also panics with no debug assertions if the value does not fit and cannot be wrapped, for example when trying to cast floating-point ∞ into an integer type.

Examples

use az::Cast;
let a: u32 = 5i32.cast();
assert_eq!(a, 5);
assert_eq!(Cast::<u8>::cast(17.1f32), 17);

Required methods

Casts the value.

Implementations on Foreign Types

Implementors