Trait easy_cast::CastFloat[][src]

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, 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>; }

Like Into, but for ConvFloat

Two sets of methods are provided:

  • cast_* methods are for “success expected” conversions. In debug builds and when using the always_assert or the assert_float feature flag, out-of-range conversions will panic. In other cases, conversions may produce incorrect values (according to the behaviour of as, which is saturating cast since Rust 1.45.0 and undefined for older compilers). Non-finite source values (inf and NaN) are considered out-of-range.
  • try_cast_* methods are for fallible conversions and always produce an error if the conversion would be out of range.

Required methods

fn cast_trunc(self) -> T[src]

Cast to integer, truncating

Rounds towards zero (same as as).

fn cast_nearest(self) -> T[src]

Cast to the nearest integer

Half-way cases are rounded away from 0.

fn cast_floor(self) -> T[src]

Cast the floor to an integer

Returns the largest integer less than or equal to self.

fn cast_ceil(self) -> T[src]

Cast the ceiling to an integer

Returns the smallest integer greater than or equal to self.

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

Try converting to integer with truncation

Rounds towards zero (same as as).

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

Try converting to the nearest integer

Half-way cases are rounded away from 0.

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

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>[src]

Try convert the ceiling to an integer

Returns the smallest integer greater than or equal to x.

Loading content...

Implementors

impl<S, T: ConvFloat<S>> CastFloat<T> for S[src]

Loading content...