Trait Smooth

Source
pub trait Smooth {
    // Required methods
    fn round_to(&self, decimals: u16) -> Self;
    fn round_to_mut(&mut self, decimals: u16);
    fn round_to_str(&self, decimals: u16) -> String;
    fn smooth(&self) -> Self;
    fn smooth_mut(&mut self);
    fn smooth_str(&self) -> String;
}
Expand description

Extension trait to make a single number human-readable.

Required Methods§

Source

fn round_to(&self, decimals: u16) -> Self

Returns the number rounded to the specified decimals.

§Examples
assert_eq!(1.1111.round_to(2), 1.11);
assert_eq!(9.9999.round_to(2), 10.0);
Source

fn round_to_mut(&mut self, decimals: u16)

Rounds the number to the specified decimals.

§Examples
let mut n = 1.1111;
n.round_to_mut(2);

assert_eq!(n, 1.11);
Source

fn round_to_str(&self, decimals: u16) -> String

Returns the formatted, rounded number.

§Examples
assert_eq!(1.0.round_to_str(2), "1");
assert_eq!(1.001.round_to_str(2), "1");
assert_eq!(1.018.round_to_str(2), "1.02");
assert_eq!(1.4242.round_to_str(2), "1.42");
Source

fn smooth(&self) -> Self

Returns the smoothed number.

§Examples
assert_eq!(0.0.smooth(), 0.0);
assert_eq!(0.009.smooth(), 0.01);
assert_eq!(1.001.smooth(), 1.0);
assert_eq!(10.1.smooth(), 10.1);
assert_eq!(1000.9.smooth(), 1001.0);
Source

fn smooth_mut(&mut self)

Smoothes the number.

§Examples
let mut n = 1.001;
n.smooth_mut();

assert_eq!(n, 1.0);
Source

fn smooth_str(&self) -> String

Returns the formatted, smoothed number.

§Examples
assert_eq!(0.0.smooth_str(), "0");
assert_eq!(0.009.smooth_str(), "0.01");
assert_eq!(1.001.smooth_str(), "1");
assert_eq!(10.1.smooth_str(), "10.1");
assert_eq!(1000.9.smooth_str(), "1001");

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Smooth for f32

Source§

fn round_to(&self, decimals: u16) -> Self

Source§

fn round_to_mut(&mut self, decimals: u16)

Source§

fn round_to_str(&self, decimals: u16) -> String

Source§

fn smooth(&self) -> Self

Source§

fn smooth_mut(&mut self)

Source§

fn smooth_str(&self) -> String

Source§

impl Smooth for f64

Source§

fn round_to(&self, decimals: u16) -> Self

Source§

fn round_to_mut(&mut self, decimals: u16)

Source§

fn round_to_str(&self, decimals: u16) -> String

Source§

fn smooth(&self) -> Self

Source§

fn smooth_mut(&mut self)

Source§

fn smooth_str(&self) -> String

Implementors§