pub trait CastFloat<T> {
    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

Like Into, but for ConvFloat

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_assert or assert_float feature flag is used, otherwise conversions have similar behaviour to the as keyword.

This trait is automatically implemented for every implementation of ConvFloat.

Required Methods§

Cast to integer, truncating

Rounds towards zero (same as as).

Cast to the nearest integer

Half-way cases are rounded away from 0.

Cast the floor to an integer

Returns the largest integer less than or equal to self.

Cast the ceiling to an integer

Returns the smallest integer greater than or equal to self.

Try converting to integer with truncation

Rounds towards zero (same as as).

Try converting to the nearest integer

Half-way cases are rounded away from 0.

Try converting the floor to an integer

Returns the largest integer less than or equal to x.

Try convert the ceiling to an integer

Returns the smallest integer greater than or equal to x.

Implementors§