Trait rin::math::cast::AsPrimitive [−][src]
A generic interface for casting between machine scalars with the
as
operator, which admits narrowing and precision loss.
Implementers of this trait AsPrimitive
should behave like a primitive
numeric type (e.g. a newtype around another primitive), and the
intended conversion must never fail.
Examples
let three: i32 = (3.14159265f32).as_(); assert_eq!(three, 3);
Safety
In Rust versions before 1.45.0, some uses of the as
operator were not entirely safe.
In particular, it was undefined behavior if
a truncated floating point value could not fit in the target integer
type (#10184).
ⓘ
let x: u8 = (1.04E+17).as_(); // UB
Required methods
Loading content...Implementations on Foreign Types
impl<T, U> AsPrimitive<U> for Complex<T> where
T: AsPrimitive<U>,
U: 'static + Copy,
[src]
impl<T, U> AsPrimitive<U> for Complex<T> where
T: AsPrimitive<U>,
U: 'static + Copy,
[src]Implementors
impl<T, U> AsPrimitive<U> for rin::math::Complex<T> where
T: AsPrimitive<U>,
U: 'static + Copy,
[src]
impl<T, U> AsPrimitive<U> for rin::math::Complex<T> where
T: AsPrimitive<U>,
U: 'static + Copy,
[src]