lim 0.1.0

A generic bounded value type for Rust featuring safe clamping, exclusive/inclusive bounds, and thiserror integration.
Documentation
use lim::{Lim, LimError};

#[test]
fn test_new_validations() {
    let ok      = Lim::new(5, 0, 10, true, true);
    let out     = Lim::new(15, 0, 10, true, true);
    let invalid = Lim::new(5, 10, 0, true, true);

    assert!(ok.is_ok());
    assert!(matches!(out.unwrap_err(), LimError::OutOfBounds { .. }));
    assert!(matches!(invalid.unwrap_err(), LimError::InvalidBounds { .. }));
}

#[test]
fn test_set_min_clamp_and_exclusive() {
    let mut lim = Lim::new(5, 0, 10, true, true).unwrap();

    let no_clamp_fail = lim.set_min(8, true, false);
    let clamp_success = lim.set_min(8, true, true);
    
    assert!(matches!(no_clamp_fail.unwrap_err(), LimError::OutOfBounds { .. }));
    assert!(clamp_success.is_ok());
    assert_eq!(*lim.value(), 8);

    let ambiguous      = lim.set_min(8, false, true);
    let exclusive_fail = lim.set_min(10, false, true);
    
    assert!(matches!(ambiguous.unwrap_err(), LimError::AmbiguousClamp { .. }));
    assert!(matches!(exclusive_fail.unwrap_err(), LimError::ExclusiveBoundClamp { .. }));
}

#[test]
fn test_set_max_clamp_and_exclusive() {
    let mut lim = Lim::new(5, 0, 10, true, true).unwrap();

    let no_clamp_fail = lim.set_max(2, true, false);
    let clamp_success = lim.set_max(2, true, true);
    
    assert!(matches!(no_clamp_fail.unwrap_err(), LimError::OutOfBounds { .. }));
    assert!(clamp_success.is_ok());
    assert_eq!(*lim.value(), 2);

    let ambiguous      = lim.set_max(2, false, true);
    let exclusive_fail = lim.set_max(0, false, true);
    
    assert!(matches!(ambiguous.unwrap_err(), LimError::AmbiguousClamp { .. }));
    assert!(matches!(exclusive_fail.unwrap_err(), LimError::ExclusiveBoundClamp { .. }));
}

#[test]
fn test_set_bounds_complex() {
    let mut lim = Lim::new(5, 0, 10, true, true).unwrap();

    let invalid = lim.set_bounds(10, 5, true, true, false);
    assert!(matches!(invalid.unwrap_err(), LimError::InvalidBounds { .. }));

    let clamp_both = lim.set_bounds(6, 8, true, true, true);
    assert!(clamp_both.is_ok());
    assert_eq!(*lim.value(), 6);

    let ambiguous_max = lim.set_bounds(2, 6, true, false, true);
    assert!(matches!(ambiguous_max.unwrap_err(), LimError::AmbiguousClamp { .. }));
}