#![feature(auto_traits, negative_impls)]
pub mod byte_size;
pub mod one_or_many;
pub mod zero_one_or_many;
pub mod json_ext;
pub use byte_size::{ByteSize, ByteSizeExt};
pub use one_or_many::OneOrMany;
pub use zero_one_or_many::ZeroOneOrMany;
#[cfg(feature = "hashbrown-json")]
pub use json_ext::{
CollectionJsonExtKString, CollectionJsonExtKV, CollectionJsonExtStringString,
CollectionJsonExtStringV, JsonObjectExtKString, JsonObjectExtKV, JsonObjectExtStringString,
JsonObjectExtStringV, TryCollectionJsonExtKString, TryCollectionJsonExtKV,
TryCollectionJsonExtStringString, TryCollectionJsonExtStringV,
};
#[cfg(feature = "hashbrown-json")]
#[macro_export]
macro_rules! hash_map {
{ $($key:expr => $value:expr),* $(,)? } => {
|| {
let mut map = ::hashbrown::HashMap::new();
$(
map.insert($key, $value);
)*
map
}
};
}
#[cfg(feature = "hashbrown-json")]
#[macro_export]
macro_rules! json_closure {
( $($input:tt)* ) => {
json_closure_internal! { $($input)* }
};
}
#[cfg(feature = "hashbrown-json")]
#[macro_export]
macro_rules! json_closure_internal {
( $($tokens:tt)* ) => {
json_closure_replace! { $($tokens)* }
};
}
#[cfg(feature = "hashbrown-json")]
#[macro_export]
macro_rules! json_closure_replace {
() => {};
( $($prefix:tt)* { $($inner:tt)+ } $($suffix:tt)* ) => {
json_closure_replace_inner! {
prefix: [ $($prefix)* ]
block: { $($inner)+ }
suffix: [ $($suffix)* ]
}
};
( $($tokens:tt)* ) => {
$($tokens)*
};
}
#[cfg(feature = "hashbrown-json")]
#[macro_export]
macro_rules! json_closure_replace_inner {
( prefix: [ $($prefix:tt)* ] block: { $($inner:tt)+ } suffix: [ $($suffix:tt)* ] ) => {
json_closure_check_arrows! {
prefix: [ $($prefix)* ]
inner: [ $($inner)+ ]
suffix: [ $($suffix)* ]
}
};
}
#[cfg(feature = "hashbrown-json")]
#[macro_export]
macro_rules! json_closure_check_arrows {
( prefix: [ $($prefix:tt)* ] inner: [ $($inner:tt)+ ] suffix: [ $($suffix:tt)* ] ) => {
json_closure_arrow_check! {
prefix: [ $($prefix)* ]
inner: [ $($inner)+ ]
suffix: [ $($suffix)* ]
}
};
}
#[cfg(feature = "hashbrown-json")]
#[macro_export]
macro_rules! json_closure_arrow_check {
( prefix: [ $($prefix:tt)* ] inner: [ $($pre:tt)* => $($post:tt)* ] suffix: [ $($suffix:tt)* ] ) => {
json_closure_replace! { $($prefix)* sugars_macros::hash_map_fn! { $($pre)* => $($post)* } $($suffix)* }
};
( prefix: [ $($prefix:tt)* ] inner: [ $($inner:tt)+ ] suffix: [ $($suffix:tt)* ] ) => {
json_closure_replace! { $($prefix)* { $($inner)+ } $($suffix)* }
};
}
#[macro_export]
macro_rules! on_result {
(Ok => $ok:expr, Err => $err:expr) => {
move |__res| match __res {
Ok(chunk) => Ok($ok),
Err(err) => Err($err),
}
};
}
#[macro_export]
macro_rules! on_chunk {
($expr:expr) => {
move |__chunk| $expr
};
}
#[macro_export]
macro_rules! on_error {
($expr:expr) => {
move |__err| $expr
};
}
#[macro_export]
macro_rules! await_result {
($param:pat => $body:expr) => {
move |$param| async move { $body }
};
}
#[macro_export]
macro_rules! await_ok {
($param:pat => $body:expr) => {
move |$param| async move {
$body;
}
};
}