pub trait Cast<T> {
// Required method
fn cast(self) -> T;
}Expand description
Unified trait for conversions between fastnum numeric types.
Cast is a total conversion: it never fails and does not return an error.
Prefer Cast when the conversion is guaranteed to be correct by definition
(e.g., widening with preserved value or sign/zero extension that cannot
overflow).
If the conversion may go out of range or lose information (sign/high bits),
use TryCast instead.
§Examples:
use fastnum::*;
let a = u128!(123);
// Lossless widening
let b: U256 = a.cast();
assert_eq!(u256!(123), b);See also: TryCast for fallible conversions.
Required Methods§
Sourcefn cast(self) -> T
fn cast(self) -> T
Performs an infallible, value-preserving conversion.
This method never fails. Use it for conversions that are known to be safe and cannot overflow or lose information (e.g., widening).
§Examples:
use fastnum::*;
let x = u128!(123);
let y: U256 = x.cast();
assert_eq!(u256!(123), y);