macro_rules! nonempty { ($h:expr, $( $x:expr ),* $(,)?) => { ... }; ($h:expr) => { ... }; }
Expand description
Like the vec! macro, but enforces at least one argument. A nice short-hand
for constructing NonEmpty values.
use nonempty::{NonEmpty, nonempty};
let v = nonempty![1, 2, 3];
assert_eq!(v, NonEmpty { head: 1, tail: vec![2, 3] });
let v = nonempty![1];
assert_eq!(v, NonEmpty { head: 1, tail: Vec::new() });
// Accepts trailing commas
let v = nonempty![1,];
assert_eq!(v, NonEmpty { head: 1, tail: Vec::new() });
// Doesn't compile!
// let v = nonempty![];