Skip to main content

Crate lim

Crate lim 

Source
Expand description

lim provides a robust, generic bounding limit type for Rust.

It allows you to define a value constrained within a specific range, with configurable inclusive or exclusive bounds. When modifying the value or the bounds, lim guarantees the constraints are maintained, offering safe clamping and fine-grained, structured error handling via thiserror.

§Examples

use lim::{Lim, LimError};

// Create a value between 0 and 10 (inclusive)
let mut health = Lim::new(10, 0, 10, true, true).unwrap();
assert_eq!(*health, 10);

// Attempt to set a value out of bounds without clamping
assert!(matches!(health.set_value(15), Err(LimError::OutOfBounds { .. })));

// Safely clamp to a new bound
health.set_max(5, true, true).unwrap();
assert_eq!(*health, 5);

Structs§

Lim
A strictly typed bounding limit that guarantees a value stays within defined constraints.

Enums§

LimError
Errors that can occur when manipulating a Lim instance.