Macro assertables::assert_set_disjoint
source · macro_rules! assert_set_disjoint { ($a:expr, $b:expr $(,)?) => { ... }; ($a:expr, $b:expr, $($message:tt)+) => { ... }; }
Expand description
Assert a set is disjoint with another.
-
If true, return
()
. -
Otherwise, call
panic!
with a message and the values of the expressions with their debug representations.
Examples
// Return Ok
let a = [1, 2];
let b = [3, 4];
assert_set_disjoint!(&a, &b);
//-> ()
// Panic with error message
let result = panic::catch_unwind(|| {
let a = [1, 2];
let b = [2, 3];
assert_set_disjoint!(&a, &b);
//-> panic!
});
assert!(result.is_err());
let actual = result.unwrap_err().downcast::<String>().unwrap().to_string();
let expect = concat!(
"assertion failed: `assert_set_disjoint!(left_set, right_set)`\n",
" left_set label: `&a`,\n",
" left_set debug: `[1, 2]`,\n",
" right_set label: `&b`,\n",
" right_set debug: `[2, 3]`,\n",
" left: `{1, 2}`,\n",
" right: `{2, 3}`"
);
assert_eq!(actual, expect);
This implementation uses [BTreeSet
] to count items and sort them.