macro_rules! for_all { ($value:expr, $pattern:pat => $result:expr) => { ... }; }
Expand description
Evaluate the provided expression for both Among::Left and Among::Right.
This macro is useful in cases where both sides of Among can be interacted with
in the same way even though the don’t share the same type.
Syntax: among::for_all!( expression , pattern => expression )
§Example
use among::Among;
use std::borrow::Cow;
fn length(owned_or_borrowed: Among<String, Cow<'static, str>, &'static str>) -> usize {
among::for_all!(owned_or_borrowed, s => s.len())
}
fn main() {
let borrowed = Among::Right("Hello world!");
let owned = Among::Left("Hello world!".to_owned());
let mixed = Among::Middle(Cow::Borrowed("Hello world!"));
assert_eq!(length(borrowed), 12);
assert_eq!(length(mixed), 12);
assert_eq!(length(owned), 12);
}