[![Latest version](https://img.shields.io/crates/v/checked_clamp.svg)](https://crates.io/crates/checked_clamp) [![pipeline status](https://gitlab.com/ygor.souza/checked_clamp/badges/main/pipeline.svg)](https://gitlab.com/ygor.souza/checked_clamp/-/commits/main) [![Documentation](https://docs.rs/checked_clamp/badge.svg)](https://docs.rs/checked_clamp) [![unsafe forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg)](https://github.com/rust-secure-code/safety-dance/) [![License](https://img.shields.io/crates/l/checked_clamp.svg)](https://crates.io/crates/checked_clamp) # 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}; assert_eq!(10.0.checked_clamp(0.0, 1.0), Ok(1.0)); assert_eq!(10.0.checked_clamp(1.0, 0.0), Err(E::MinGreaterThanMax)); assert_eq!(f32::NAN.checked_clamp(0.0, 10.0), Err(E::ComparisonFailed)); assert_eq!(0.0.checked_clamp(f32::NAN, 10.0), Err(E::ComparisonFailed)); assert_eq!("ABCD".checked_clamp("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 - Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or ) - MIT license ([LICENSE-MIT](LICENSE-MIT) or ) at your option.