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§
sourcefn try_round_to(self, factor: Self) -> Option<Self>
fn try_round_to(self, factor: Self) -> Option<Self>
Round to the nearest factor.
Provided Methods§
Object Safety§
This trait is not object safe.