Trait roundable::Roundable

source ·
pub trait Roundable: Sized {
    // Required method
    fn try_round_to(self, factor: Self) -> Option<Self>;

    // Provided method
    fn round_to(self, factor: Self) -> Self { ... }
}
Expand description

Add methods to round to an arbitrary factor.

For example, you might wish to round an integer to the nearest 10s:

use roundable::Roundable;

assert!(310 == 314.round_to(10));
assert!(300 == 314.round_to(100));

Required Methods§

source

fn try_round_to(self, factor: Self) -> Option<Self>

Round to the nearest factor.

Provided Methods§

source

fn round_to(self, factor: Self) -> Self

Round to the nearest factor.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Roundable for f32

source§

fn try_round_to(self, factor: Self) -> Option<Self>

source§

impl Roundable for f64

source§

fn try_round_to(self, factor: Self) -> Option<Self>

source§

impl Roundable for i8

source§

fn try_round_to(self, factor: Self) -> Option<Self>

source§

impl Roundable for i16

source§

fn try_round_to(self, factor: Self) -> Option<Self>

source§

impl Roundable for i32

source§

fn try_round_to(self, factor: Self) -> Option<Self>

source§

impl Roundable for i64

source§

fn try_round_to(self, factor: Self) -> Option<Self>

source§

impl Roundable for i128

source§

fn try_round_to(self, factor: Self) -> Option<Self>

source§

impl Roundable for isize

source§

fn try_round_to(self, factor: Self) -> Option<Self>

source§

impl Roundable for u8

source§

fn try_round_to(self, factor: Self) -> Option<Self>

source§

impl Roundable for u16

source§

fn try_round_to(self, factor: Self) -> Option<Self>

source§

impl Roundable for u32

source§

fn try_round_to(self, factor: Self) -> Option<Self>

source§

impl Roundable for u64

source§

fn try_round_to(self, factor: Self) -> Option<Self>

source§

impl Roundable for u128

source§

fn try_round_to(self, factor: Self) -> Option<Self>

source§

impl Roundable for usize

source§

fn try_round_to(self, factor: Self) -> Option<Self>

source§

impl Roundable for Duration

source§

fn try_round_to(self, factor: Self) -> Option<Self>

Implementors§