[][src]Macro col_macros::vector

macro_rules! vector {
    (for $map:expr, ins $( $k:literal ),*) => { ... };
    (for $map:expr, ins $( $k:expr ),*) => { ... };
    (for $map:tt, ins $( $k:tt ,)*) => { ... };
    ( $( $k:literal ),*) => { ... };
    ( $( $k:expr ),*) => { ... };
    ( $e:literal; $n:literal) => { ... };
    ( $e:expr; $n:literal) => { ... };
    ( $e:literal; $n:expr) => { ... };
    ( $e:expr; $n:expr) => { ... };
    (for $map:expr, ins $e:literal; $n:literal) => { ... };
    (for $map:expr, ins $e:expr; $n:literal) => { ... };
    (for $map:expr, ins $e:literal; $n:expr) => { ... };
    (for $map:expr, ins $e:expr; $n:expr) => { ... };
    ( $( $k:tt ,)*) => { ... };
}

Construct or update a vector of type Vector<T> which can be and is an alias to Vec in the types module.

Collections with the with_capacity and set_len methods that deref to [T] are accepted.

Why not vec!?

  1. Does not take in account where the input is an identifier or literal and does not apply optimizations based on that.

  2. It is not general purpose,it always construct a Vec.

Examples

#![feature(proc_macro_hygiene)]
use col_macros::vector;
use col_macros::types::Vector;

let mut vec1: Vec<usize> = vector![1, 2, 3];
let eight: usize = 8;

assert_eq!(vec1, vec![1, 2, 3]);

vector![for &mut vec1, ins 4, 5, 6, eight].push(7); // we still have a mutable reference

assert_eq!(vec1, vector![1, 2, 3, 4, 5, 6, eight, 7]);

assert_eq!(vec![eight; 8], vector![eight; eight]);
assert_eq!(vec![8, 8, 8], vector![eight, eight, eight]);
assert_eq!(vec![8, 8, 8], vector![eight, eight, 8]);