macro_rules! with_ord {
($items:expr, $cmp:expr, $body:expr) => { ... };
}Expand description
Wraps items in WithContext<T, OrdContext<T>> with
a custom comparator, runs a callback, and provides the wrapped slice.
ยงExamples
use context_trait::{with_ord, WithContext, OrdContext};
let items = vec![3i32, 1, 4, 1, 5];
with_ord!(items, |a: &i32, b: &i32| b.cmp(a), |wrapped: &[WithContext<i32, OrdContext<i32>>]| {
let mut sorted = wrapped.to_vec();
sorted.sort();
let values: Vec<i32> = sorted.into_iter().map(|w| w.inner).collect();
assert_eq!(values, vec![5, 4, 3, 1, 1]);
});