lim 0.1.0

A generic bounded value type for Rust featuring safe clamping, exclusive/inclusive bounds, and thiserror integration.
Documentation
  • Coverage
  • 72%
    18 out of 25 items documented1 out of 14 items with examples
  • Size
  • Source code size: 24.5 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 499.8 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 12s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Underline-1024

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.