nev

Macro nev 

Source
macro_rules! nev {
    ($elem:expr; $n:expr) => { ... };
    ($single:expr) => { ... };
    ($head:expr, $($tail:expr),+ $(,)?) => { ... };
}
Expand description

Creates a [NonEmptyVec] containing the arguments.

This macro is very similar in goal to the standard library’s vec! macro:

  • Create a [NonEmptyVec] containing a given list of elements:
let ne = nev![1, 2, 3];
assert_eq!(ne[0], 1);
assert_eq!(ne[1], 2);
assert_eq!(ne[2], 3);
  • Create a [NonEmptyVec] from a given head element and tail vector.
let vec = vec![2, 3, 4];
let ne = nev![1; vec];
assert_eq!(ne, NEVec::from_vec(vec![1, 2, 3, 4]).unwrap());

Note that unlike Vecs, it is not possible to create an empty [NonEmptyVec] using this macro!