#字面量 #迭代器 #展开 #vec

lit-vek

iter!和vek!宏,用于更简洁的字面量语法

1个不稳定版本

0.1.0 2023年3月14日

#10 in #展开

MIT/Apache

12KB
146

vek

Rust包,定义宏以启用类似ES的“展开”语法用于字面量序列。

    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包,定义宏以启用类似ES的“展开”语法用于字面量序列。

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();

无运行时依赖