#literals #iterator #spread #vec

lit-vek

iter! and vek! macros for nicer literal syntax

1 unstable release

0.1.0 Mar 14, 2023

#2549 in Rust patterns

MIT/Apache

12KB
146 lines

vek

Rust crate that defines macros to enable ES-like "spread" syntax for literal sequences.

    let arr = [4, 5, 6];

    // `vek!` is a drop-in replacement for `std::vec!`, except you can
    // use `...x` to expand iterables.
    assert_eq!(
        vek![1, 2, 3, ...arr, 7, 8, 9],
        [1, 2, 3, 4, 5, 6, 7, 8, 9]);

    // `iter!` provides the same syntax but produces an `Iterator`.
    # use std::collections::VecDeque;
    let d: VecDeque<_> = iter![1, 2, 3, ...arr, 7, 8, 9].collect();

lib.rs:

Rust crate that defines macros to enable ES-like "spread" syntax for literal sequences.

let arr = [4, 5, 6];

// `vek!` is a drop-in replacement for `std::vec!`, except you can
// use `...x` to expand iterables.
assert_eq!(
vek![1, 2, 3, ...arr, 7, 8, 9],
[1, 2, 3, 4, 5, 6, 7, 8, 9]);

assert_eq!(
vek![1, 2, 3, ...arr, 7, 8, 9],
[1, 2, 3, 4, 5, 6, 7, 8, 9]);

// `iter!` provides the same syntax as iterator, similar to
// itertools::chain()
let d: VecDeque<_> = iter![1, 2, 3, ...arr, 7, 8, 9].collect();

No runtime deps