Crate roundable

source ·
Expand description

§Roundable values

This provides an implementation of rounding for various values, including std::time::Duration.

use roundable::Roundable;

assert!(310 == 314.round_to(10));
assert!(300.0 == 314.1.round_to(100.0));

See Constants for a list of time units that make rounding Duration easier.

use roundable::{SECOND, MINUTE, Roundable};
use std::time::Duration;

assert!(Duration::ZERO == Duration::from_millis(314).round_to(SECOND));
assert!(MINUTE == Duration::from_millis(59_500).round_to(SECOND));

§Minimum supported Rust version

Currently the minimum supported Rust version (MSRV) is 1.56.1. Future increases in the MSRV will require a major version bump.

Constants§

Traits§

  • Add methods to round to an arbitrary factor.

Functions§