Latest version pipeline status Documentation unsafe forbidden License

Checked clamp

checked_clamp provides a method that tries to clamp any type implementing PartialOrd between a minimum and a maximum value, returning an error if the value or the limits are invalid.

Example

```rust use checked_clamp::{CheckedClamp, CheckedClampError as E};

asserteq!(10.0.checkedclamp(0.0, 1.0), Ok(1.0)); asserteq!(10.0.checkedclamp(1.0, 0.0), Err(E::MinGreaterThanMax)); asserteq!(f32::NAN.checkedclamp(0.0, 10.0), Err(E::ComparisonFailed)); asserteq!(0.0.checkedclamp(f32::NAN, 10.0), Err(E::ComparisonFailed)); asserteq!("ABCD".checkedclamp("AAA", "ZZZ"), Ok("ABCD")); ```

Contributing

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as below, without any additional terms or conditions.

License

Licensed under either of

at your option.