#bounds #numbers #range #ord #anything #self #automatic

num_bound

Add bounds fn to anything implementing Ord that bounds a number to a range

3 releases

0.1.2 May 18, 2022
0.1.1 May 17, 2022
0.1.0 May 17, 2022

#2648 in Rust patterns

Download history 11/week @ 2024-02-23 8/week @ 2024-03-01 1/week @ 2024-03-08 3/week @ 2024-03-15 40/week @ 2024-03-29 11/week @ 2024-04-05

51 downloads per month

Custom license

7KB

num_bound

Trait that adds a bound function enabling to restrict a number to a range.

Automatically implemented for anything that implements std trait Ord.

Usage

bound(&self, lower: &Self, upper: &Self) -> &Self


use num_bound::Bound;

#[test]
fn bound_test()
{
    let lower = 200;
    let upper = 500;

    let out_lower = 100;
    let out_upper = 600;
    let in_bounds = 300;
    
    assert_eq!(out_lower.bound(&l, &u), &lower);
    assert_eq!(out_upper.bound(&l, &u), &upper);
    assert_eq!(in_bounds.bound(&l, &u), &in_bounds);
}

No runtime deps