macro_rules! assertable_f_ok_le {
    ($function:path, $left:expr, $right:expr $(,)?) => { ... };
    ($function:path, $left:expr, $right:expr, $($arg:tt)+) => { ... };
}
Expand description

Assert one function ok() is less than or equal to another function ok().

  • When true, return Ok(()).

  • Otherwise, return Err with a message and the values of the expressions with their debug representations.

Examples

fn example_digit_to_string(i: isize) -> Result<String, String> {
    match i {
        0..=9 => Ok(format!("{}", i)),
        _ => Err(format!("{:?} is out of range", i)),
    }
}
 
let x = assertable_f_ok_le!(example_digit_to_string, 1, 2);
//-> Ok(())
assert_eq!(x.unwrap(), ());

let x = assertable_f_ok_le!(example_digit_to_string, 2, 1);
//-> Err("…")
// assertable failed: `assertable_f_ok_le!(function, left, right)`
//      function: `\"example_digit_to_string\"`,
//    left input: `2`,
//   right input: `1`,
//   left output: `\"2\"`,
//  right output: `\"1\"`
assert_eq!(x.unwrap_err(), "assertable failed: `assertable_f_ok_le!(function, left, right)`\n     function: `\"example_digit_to_string\"`,\n   left input: `2`,\n  right input: `1`,\n  left output: `\"2\"`,\n right output: `\"1\"`".to_string());

This macro has a second form where a custom message can be provided.