Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lim

A robust, generic bounding limit type for Rust.

Getting Started

Installation

cargo add lim

Basic Usage

use 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

Features

  • Generic Bounds: Supports any type implementing PartialOrd, Clone, and Debug.
  • 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 Deref trait, allowing intuitive and direct access to the underlying value.

License

This project is licensed under the MIT License.

About

Generic bounded values in Rust. Features inclusive/exclusive bounds, safe clamping, structured errors, and out-of-the-box Serde support.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages