1 use serde_test::Token; 2 use std::iter; 3 4 macro_rules! btreeset { 5 () => { 6 BTreeSet::new() 7 }; 8 ($($value:expr),+) => {{ 9 let mut set = BTreeSet::new(); 10 $(set.insert($value);)+ 11 set 12 }}; 13 } 14 15 macro_rules! btreemap { 16 () => { 17 BTreeMap::new() 18 }; 19 ($($key:expr => $value:expr),+) => {{ 20 let mut map = BTreeMap::new(); 21 $(map.insert($key, $value);)+ 22 map 23 }}; 24 } 25 26 macro_rules! hashset { 27 () => { 28 HashSet::new() 29 }; 30 ($($value:expr),+) => {{ 31 let mut set = HashSet::new(); 32 $(set.insert($value);)+ 33 set 34 }}; 35 ($hasher:ident @ $($value:expr),+) => {{ 36 use std::hash::BuildHasherDefault; 37 let mut set = HashSet::with_hasher(BuildHasherDefault::<$hasher>::default()); 38 $(set.insert($value);)+ 39 set 40 }}; 41 } 42 43 macro_rules! hashmap { 44 () => { 45 HashMap::new() 46 }; 47 ($($key:expr => $value:expr),+) => {{ 48 let mut map = HashMap::new(); 49 $(map.insert($key, $value);)+ 50 map 51 }}; 52 ($hasher:ident @ $($key:expr => $value:expr),+) => {{ 53 use std::hash::BuildHasherDefault; 54 let mut map = HashMap::with_hasher(BuildHasherDefault::<$hasher>::default()); 55 $(map.insert($key, $value);)+ 56 map 57 }}; 58 } 59 60 pub trait SingleTokenIntoIterator { into_iter(self) -> iter::Once<Token>61 fn into_iter(self) -> iter::Once<Token>; 62 } 63 64 impl SingleTokenIntoIterator for Token { into_iter(self) -> iter::Once<Token>65 fn into_iter(self) -> iter::Once<Token> { 66 iter::once(self) 67 } 68 } 69 70 macro_rules! seq { 71 ($($elem:expr),* $(,)?) => {{ 72 use crate::macros::SingleTokenIntoIterator; 73 let mut vec = Vec::new(); 74 $(<Vec<Token> as Extend<Token>>::extend(&mut vec, $elem.into_iter());)* 75 vec 76 }}; 77 } 78