#macro #compare #multiple-values #multi #concise #comparing

multi_compare

Macro for comparing multiple values in a concise way. (a < b < c)

1 unstable release

Uses new Rust 2024

new 0.1.0 Mar 14, 2025

#570 in Math

MIT license

5KB
60 lines

Multi-Compare

This crate provides a macro to compare multiple values in a single expression without the need for the && operator and without duplicating values.

Example

use multi_compare::c;
 
fn main (){
    let mut a = 5;
    let mut b = 10;
    let mut c = 18;
     
    assert!(c!(a < b <= c));    
    assert!(c!(1 <= a < b <= c < 20));    
}

lib.rs:

Multi-Compare

This crate provides a macro to compare multiple values in a single expression without the need of the && operator and without duplicating the values.

Example

use multi_compare::c;

fn main (){
    let mut a = 5;
    let mut b = 10;
    let mut c = 18;
    
    assert!(c!(a < b <= c));    
    assert!(c!(1 <= a < b <= c < 20));    
}

No runtime deps