pub trait CastFloat<T> {
// Required methods
fn cast_trunc(self) -> T;
fn cast_nearest(self) -> T;
fn cast_floor(self) -> T;
fn cast_ceil(self) -> T;
fn try_cast_trunc(self) -> Result<T>;
fn try_cast_nearest(self) -> Result<T>;
fn try_cast_floor(self) -> Result<T>;
fn try_cast_ceil(self) -> Result<T>;
}Expand description
Use:
-
try_cast_*methods to explicitly handle errors -
cast_*methods only where success is expected. Implementations are permitted to panic or silently return a different (safe, defined) value on error.In debug builds, implementations must panic.
Implementations by this library will panic in debug builds or if the
always_assertorassert_floatfeature flag is used, otherwise conversions have similar behaviour to theaskeyword.
This trait is automatically implemented for every implementation of
ConvFloat.
Required Methods§
Sourcefn cast_trunc(self) -> T
fn cast_trunc(self) -> T
Cast to integer, truncating
Rounds towards zero (same as as).
Sourcefn cast_nearest(self) -> T
fn cast_nearest(self) -> T
Cast to the nearest integer
Half-way cases are rounded away from 0.
Sourcefn cast_floor(self) -> T
fn cast_floor(self) -> T
Cast the floor to an integer
Returns the largest integer less than or equal to self.
Sourcefn cast_ceil(self) -> T
fn cast_ceil(self) -> T
Cast the ceiling to an integer
Returns the smallest integer greater than or equal to self.
Sourcefn try_cast_trunc(self) -> Result<T>
fn try_cast_trunc(self) -> Result<T>
Try converting to integer with truncation
Rounds towards zero (same as as).
Sourcefn try_cast_nearest(self) -> Result<T>
fn try_cast_nearest(self) -> Result<T>
Try converting to the nearest integer
Half-way cases are rounded away from 0.
Sourcefn try_cast_floor(self) -> Result<T>
fn try_cast_floor(self) -> Result<T>
Try converting the floor to an integer
Returns the largest integer less than or equal to x.
Sourcefn try_cast_ceil(self) -> Result<T>
fn try_cast_ceil(self) -> Result<T>
Try convert the ceiling to an integer
Returns the smallest integer greater than or equal to x.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".