#[macro_export(local_inner_macros)]
macro_rules! value {
($($json:tt)+) => {
value_internal!($($json)+)
};
}
#[macro_export(local_inner_macros)]
#[doc(hidden)]
macro_rules! value_internal {
(@array [$($elems:expr,)*]) => {
value_internal_vec![$($elems,)*]
};
(@array [$($elems:expr),*]) => {
value_internal_vec![$($elems),*]
};
(@array [$($elems:expr,)*] null $($rest:tt)*) => {
value_internal!(@array [$($elems,)* value_internal!(null)] $($rest)*)
};
(@array [$($elems:expr,)*] true $($rest:tt)*) => {
value_internal!(@array [$($elems,)* value_internal!(true)] $($rest)*)
};
(@array [$($elems:expr,)*] false $($rest:tt)*) => {
value_internal!(@array [$($elems,)* value_internal!(false)] $($rest)*)
};
(@array [$($elems:expr,)*] [$($array:tt)*] $($rest:tt)*) => {
value_internal!(@array [$($elems,)* value_internal!([$($array)*])] $($rest)*)
};
(@array [$($elems:expr,)*] {$($map:tt)*} $($rest:tt)*) => {
value_internal!(@array [$($elems,)* value_internal!({$($map)*})] $($rest)*)
};
(@array [$($elems:expr,)*] $next:expr, $($rest:tt)*) => {
value_internal!(@array [$($elems,)* value_internal!($next),] $($rest)*)
};
(@array [$($elems:expr,)*] $last:expr) => {
value_internal!(@array [$($elems,)* value_internal!($last)])
};
(@array [$($elems:expr),*] , $($rest:tt)*) => {
value_internal!(@array [$($elems,)*] $($rest)*)
};
(@array [$($elems:expr),*] $unexpected:tt $($rest:tt)*) => {
value_unexpected!($unexpected)
};
(@object $object:ident () () ()) => {};
(@object $object:ident [$($key:tt)+] ($value:expr) , $($rest:tt)*) => {
let _ = $object.insert($crate::key_str($($key)+), $value);
value_internal!(@object $object () ($($rest)*) ($($rest)*));
};
(@object $object:ident [$($key:tt)+] ($value:expr) $unexpected:tt $($rest:tt)*) => {
value_unexpected!($unexpected);
};
(@object $object:ident [$($key:tt)+] ($value:expr)) => {
$object.insert($crate::key_str($($key)+), $value);
};
(@object $object:ident ($($key:tt)+) (: null $($rest:tt)*) $copy:tt) => {
value_internal!(@object $object [$($key)+] (value_internal!(null)) $($rest)*);
};
(@object $object:ident ($($key:tt)+) (: true $($rest:tt)*) $copy:tt) => {
value_internal!(@object $object [$($key)+] (value_internal!(true)) $($rest)*);
};
(@object $object:ident ($($key:tt)+) (: false $($rest:tt)*) $copy:tt) => {
value_internal!(@object $object [$($key)+] (value_internal!(false)) $($rest)*);
};
(@object $object:ident ($($key:tt)+) (: [$($array:tt)*] $($rest:tt)*) $copy:tt) => {
value_internal!(@object $object [$($key)+] (value_internal!([$($array)*])) $($rest)*);
};
(@object $object:ident ($($key:tt)+) (: {$($map:tt)*} $($rest:tt)*) $copy:tt) => {
value_internal!(@object $object [$($key)+] (value_internal!({$($map)*})) $($rest)*);
};
(@object $object:ident ($($key:tt)+) (: $value:expr , $($rest:tt)*) $copy:tt) => {
value_internal!(@object $object [$($key)+] (value_internal!($value)) , $($rest)*);
};
(@object $object:ident ($($key:tt)+) (: $value:expr) $copy:tt) => {
value_internal!(@object $object [$($key)+] (value_internal!($value)));
};
(@object $object:ident ($($key:tt)+) (:) $copy:tt) => {
value_internal!();
};
(@object $object:ident ($($key:tt)+) () $copy:tt) => {
value_internal!();
};
(@object $object:ident () (: $($rest:tt)*) ($colon:tt $($copy:tt)*)) => {
value_unexpected!($colon);
};
(@object $object:ident ($($key:tt)*) (, $($rest:tt)*) ($comma:tt $($copy:tt)*)) => {
value_unexpected!($comma);
};
(@object $object:ident () (($key:expr) : $($rest:tt)*) $copy:tt) => {
value_internal!(@object $object ($key) (: $($rest)*) (: $($rest)*));
};
(@object $object:ident ($($key:tt)*) (: $($unexpected:tt)+) $copy:tt) => {
value_expect_expr_comma!($($unexpected)+);
};
(@object $object:ident ($($key:tt)*) ($tt:tt $($rest:tt)*) $copy:tt) => {
value_internal!(@object $object ($($key)* $tt) ($($rest)*) ($($rest)*));
};
(null) => {
$crate::DecodedValue::Null
};
(true) => {
$crate::DecodedValue::Bool(true)
};
(false) => {
$crate::DecodedValue::Bool(false)
};
([]) => {
$crate::DecodedValue::Array(value_internal_vec![])
};
([ $($tt:tt)+ ]) => {
$crate::DecodedValue::Array(value_internal!(@array [] $($tt)+))
};
({}) => {
$crate::DecodedValue::Object($crate::DecodedObject::new())
};
({ $($tt:tt)+ }) => {
$crate::DecodedValue::Object({
let mut object = $crate::DecodedObject::new();
value_internal!(@object object () ($($tt)+) ($($tt)+));
object
})
};
($other:expr) => {
<_ as ::core::convert::Into<$crate::DecodedValue<'_>>>::into((&$other))
};
}
#[macro_export]
#[doc(hidden)]
macro_rules! value_internal_vec {
($($content:tt)*) => {
vec![$($content)*]
};
}
#[macro_export]
#[doc(hidden)]
macro_rules! value_unexpected {
() => {};
}
#[macro_export]
#[doc(hidden)]
macro_rules! value_expect_expr_comma {
($e:expr , $($tt:tt)*) => {};
}
#[macro_export]
macro_rules! clear {
( $name:ident in $x:expr ) => {
#[allow(unused_mut)]
let mut $name = &mut ($x); #[allow(unused_mut)]
let mut $name = $name._clear(); };
( $name:ident ) => {
#[allow(unused_mut)]
let mut $name = &mut $name;
#[allow(unused_mut)]
let mut $name = $name._clear();
};
}
#[macro_export]
macro_rules! rewind {
( $name:ident in $x:expr ) => {
#[allow(unused_mut)]
let mut $name = &mut ($x); #[allow(unused_mut)]
let mut $name = $name._rewind();
};
( $name:ident ) => {
#[allow(unused_mut)]
let mut $name = &mut $name;
#[allow(unused_mut)]
let mut $name = $name._rewind();
}
}
#[macro_export]
macro_rules! pool {
( $name:ident ) => {
let mut $name = MemoryPool::new();
clear!($name);
}
}