roundable 0.1.1

Round numbers and durations to a given factor
Documentation

Round numbers and durations to a given factor

docs.rs Crates.io Rust version 1.56.1+

This provides an implementation of rounding for various values, including the native number types and core::time::Duration (or std::time::Duration).

This crate is does not need std or alloc (it’s always in no_std mode). No features need to be enabled or disabled.

use roundable::Roundable;

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

// To avoid panicking on overflow:
assert!(Some(260) == 255.try_round_to(10));
assert!(None == 255u8.try_round_to(10));

See the list of 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));

⚠️ Development status

This is in active development. The API may be entirely rewritten. I am open to suggestions.

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.

License

This project dual-licensed under the Apache 2 and MIT licenses. You may choose to use either.

Contributions

Unless you explicitly state otherwise, any contribution you submit as defined in the Apache 2.0 license shall be dual licensed as above, without any additional terms or conditions.