Trait kas::cast::CastFloat

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, Error>;
    fn try_cast_nearest(self) -> Result<T, Error>;
    fn try_cast_floor(self) -> Result<T, Error>;
    fn try_cast_ceil(self) -> Result<T, Error>;
}
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§

fn cast_trunc(self) -> T

Cast to integer, truncating

Rounds towards zero (same as as).

fn cast_nearest(self) -> T

Cast to the nearest integer

Half-way cases are rounded away from 0.

fn cast_floor(self) -> T

Cast the floor to an integer

Returns the largest integer less than or equal to self.

fn cast_ceil(self) -> T

Cast the ceiling to an integer

Returns the smallest integer greater than or equal to self.

fn try_cast_trunc(self) -> Result<T, Error>

Try converting to integer with truncation

Rounds towards zero (same as as).

fn try_cast_nearest(self) -> Result<T, Error>

Try converting to the nearest integer

Half-way cases are rounded away from 0.

fn try_cast_floor(self) -> Result<T, Error>

Try converting the floor to an integer

Returns the largest integer less than or equal to x.

fn try_cast_ceil(self) -> Result<T, Error>

Try convert the ceiling to an integer

Returns the smallest integer greater than or equal to x.

Implementors§

§

impl<S, T> CastFloat<T> for S
where T: ConvFloat<S>,