A robust, generic bounding limit type for Rust.
cargo add limuse lim::{Lim, LimError};
fn main() {
// Create a value bounded between 0 and 10 (inclusive)
let mut health = Lim::new(10, 0, 10, true, true).unwrap();
// Reading the value via Deref
assert_eq!(*health, 10);
// Attempting to set an out-of-bounds value returns a structured error
let result = health.set_value(15);
assert!(matches!(result, Err(LimError::OutOfBounds { .. })));
}- Documentation — Complete documentation for this library.
- Generic Bounds: Supports any type implementing
PartialOrd,Clone, andDebug. - Flexible Bounds: Independently configure lower and upper bounds as inclusive (
>=/<=) or exclusive (>/<). - Safe Clamping: Offers optional automatic clamping when updating bounds, with strict mathematical protections for exclusive bounds to prevent ambiguity.
- Strict Serde Support: Built-in serialization and deserialization implementations that strictly enforce bound invariants during parsing.
- Transparent Value Access: Implements the
Dereftrait, allowing intuitive and direct access to the underlying value.
This project is licensed under the MIT License.