Trait mutils::num::ToRounded[][src]

pub trait ToRounded<N> {
    fn to_rounded(self) -> N;
}
Expand description

When you convert between numeric types, there are some common issues you run into.

  • Some of those types will truncate. i.e. 300_u32 as u8 gives 44.
  • Converting from a float to an integer, always round towards zero. i.e. 1.8 gives 1.

This trait exists to give a uniform way of converting from one type to another, where the result is rounded to the max value available.

It includes implementations for types where you can use ‘as’, as this provides uniformity.

Required methods

Returns the value in the new type, but clamped.

Implementations on Foreign Types

Implementors