ad3335e5d6
Since we know exactly how many bytes we should serialize as we can hint to the serializer that it is not required which further reduces the serialized size when compared to just serializing as bytes.
102 lines
2.3 KiB
Rust
102 lines
2.3 KiB
Rust
// Copyright 2017 Serde Developers
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
// option. This file may not be copied, modified, or distributed
|
|
// except according to those terms.
|
|
|
|
macro_rules! btreeset {
|
|
() => {
|
|
BTreeSet::new()
|
|
};
|
|
($($value:expr),+) => {
|
|
{
|
|
let mut set = BTreeSet::new();
|
|
$(set.insert($value);)+
|
|
set
|
|
}
|
|
}
|
|
}
|
|
|
|
macro_rules! btreemap {
|
|
() => {
|
|
BTreeMap::new()
|
|
};
|
|
($($key:expr => $value:expr),+) => {
|
|
{
|
|
let mut map = BTreeMap::new();
|
|
$(map.insert($key, $value);)+
|
|
map
|
|
}
|
|
}
|
|
}
|
|
|
|
macro_rules! hashset {
|
|
() => {
|
|
HashSet::new()
|
|
};
|
|
($($value:expr),+) => {
|
|
{
|
|
let mut set = HashSet::new();
|
|
$(set.insert($value);)+
|
|
set
|
|
}
|
|
};
|
|
($hasher:ident @ $($value:expr),+) => {
|
|
{
|
|
use std::hash::BuildHasherDefault;
|
|
let mut set = HashSet::with_hasher(BuildHasherDefault::<$hasher>::default());
|
|
$(set.insert($value);)+
|
|
set
|
|
}
|
|
}
|
|
}
|
|
|
|
macro_rules! hashmap {
|
|
() => {
|
|
HashMap::new()
|
|
};
|
|
($($key:expr => $value:expr),+) => {
|
|
{
|
|
let mut map = HashMap::new();
|
|
$(map.insert($key, $value);)+
|
|
map
|
|
}
|
|
};
|
|
($hasher:ident @ $($key:expr => $value:expr),+) => {
|
|
{
|
|
use std::hash::BuildHasherDefault;
|
|
let mut map = HashMap::with_hasher(BuildHasherDefault::<$hasher>::default());
|
|
$(map.insert($key, $value);)+
|
|
map
|
|
}
|
|
}
|
|
}
|
|
|
|
macro_rules! seq_impl {
|
|
(seq $first:expr,) => {
|
|
seq_impl!(seq $first)
|
|
};
|
|
($first:expr,) => {
|
|
seq_impl!($first)
|
|
};
|
|
(seq $first:expr) => {
|
|
$first.into_iter()
|
|
};
|
|
($first:expr) => {
|
|
Some($first).into_iter()
|
|
};
|
|
(seq $first:expr , $( $elem: tt)*) => {
|
|
$first.into_iter().chain(seq!( $($elem)* ))
|
|
};
|
|
($first:expr , $($elem: tt)*) => {
|
|
Some($first).into_iter().chain(seq!( $($elem)* ))
|
|
}
|
|
}
|
|
macro_rules! seq {
|
|
($($tt: tt)*) => {
|
|
seq_impl!($($tt)*).collect::<Vec<_>>()
|
|
};
|
|
}
|