Function az::cast[][src]

pub fn cast<Src: Cast<Dst>, Dst>(src: Src) -> Dst

Casts the value.

Panics

When debug assertions are enabled, 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 wrapping_cast instead.

This function 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

assert_eq!(az::cast::<i32, u32>(5), 5);
assert_eq!(az::cast::<f32, u8>(17.1), 17);