svec/
lib.rs

1//! This crates provides a macro `svec` that allows for Dart-style lists in Rust
2
3use proc_macro_hack::proc_macro_hack;
4
5/// A macro that expands to a literal `Vec`
6#[proc_macro_hack]
7pub use svec_macro::svec;
8
9#[cfg(test)]
10mod tests {
11    #[test]
12    fn it_works() {
13        let n = 38;
14        let x = svec![
15            0,
16            5,
17            for i in 0..10 {
18                i
19            },
20            for i in 0..10 {
21                if i > 5 { i } else { 0 }
22            },
23            if n > 100 { 2 } else if n > 60 { 1 } else { 0 },
24            if n < 50 { 10 }
25        ];
26
27        assert_eq!(
28            x,
29            vec![0, 5, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 6, 7, 8, 9, 0, 10]
30        );
31    }
32}