#[doc(hidden)]
#[macro_export]
macro_rules! __no_read_only {
() => {
::core::compile_error!(
"structio: a declaration narrows to the write half or to neither, \
so there is no `read_only`. A type that is only ever read still \
generates its write impls, and its fields still need them: a \
field with nothing to say on the way out writes `null`, with \
`is_null` returning `true` so that `SkipNull` drops the member"
);
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __write_only_is_the_marker {
() => {
::core::compile_error!(
"structio: `write_only` in front of a declaration is the marker \
that narrows it to the write half, so `write_only::..` was read \
as that marker followed by a stray `::`. Name the type without \
the leading `::`, or bring it into scope with a `use` and name \
it there"
);
};
}
#[macro_export]
macro_rules! object {
(write_only :: $($t:tt)*) => { $crate::__write_only_is_the_marker!(); };
(read_only $($t:tt)*) => { $crate::__no_read_only!(); };
(write_only $($t:tt)*) => { $crate::__declare!([write] __both_write_impls $($t)*); };
($($t:tt)*) => { $crate::__declare!([both] __both_impls $($t)*); };
}
#[macro_export]
macro_rules! json_object {
(write_only :: $($t:tt)*) => { $crate::__write_only_is_the_marker!(); };
(read_only $($t:tt)*) => { $crate::__no_read_only!(); };
(write_only $($t:tt)*) => { $crate::__declare!([write] __json_write_impls $($t)*); };
($($t:tt)*) => { $crate::__declare!([both] __json_impls $($t)*); };
}
#[macro_export]
macro_rules! beve_object {
(write_only :: $($t:tt)*) => { $crate::__write_only_is_the_marker!(); };
(read_only $($t:tt)*) => { $crate::__no_read_only!(); };
(write_only $($t:tt)*) => { $crate::__declare!([write] __beve_write_impls $($t)*); };
($($t:tt)*) => { $crate::__declare!([both] __beve_impls $($t)*); };
}
#[doc(hidden)]
#[macro_export]
macro_rules! __declare {
([$dir:tt] $m:ident [ $de:lifetime $($gen:tt)* ] $ty:ty as $case:tt { $($body:tt)* }) => {
$crate::__declared!([$dir] $m [$de $($gen)*] [$de $($gen)*] [$case] $ty { $($body)* });
};
([$dir:tt] $m:ident [ $de:lifetime $($gen:tt)* ] $ty:ty { $($body:tt)* }) => {
$crate::__declared!([$dir] $m [$de $($gen)*] [$de $($gen)*] [_] $ty { $($body)* });
};
([$dir:tt] $m:ident [ $($gen:tt)* ] $ty:ty as $case:tt { $($body:tt)* }) => {
$crate::__declared!([$dir] $m ['de, $($gen)*] [$($gen)*] [$case] $ty { $($body)* });
};
([$dir:tt] $m:ident [ $($gen:tt)* ] $ty:ty { $($body:tt)* }) => {
$crate::__declared!([$dir] $m ['de, $($gen)*] [$($gen)*] [_] $ty { $($body)* });
};
([$dir:tt] $m:ident $ty:ty as $case:tt { $($body:tt)* }) => {
$crate::__declared!([$dir] $m ['de] [] [$case] $ty { $($body)* });
};
([$dir:tt] $m:ident $ty:ty { $($body:tt)* }) => {
$crate::__declared!([$dir] $m ['de] [] [_] $ty { $($body)* });
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __declared {
([$dir:tt] $m:ident [$($rgen:tt)*] [$($wgen:tt)*] [$case:tt] $ty:ty {
$($(#[$req:ident])? $($key:literal =>)? $field:ident $(as $with:ty)? $(| $alias:literal)* ,)* ..
}) => {
$crate::__case_check!($case);
$crate::__keys_impl!([$($wgen)*] [$case] [partial] [$dir] $ty {
$($(#[$req])? $($key =>)? $field $(as $with)? $(| $alias)*),*
});
$crate::$m!([$($rgen)*] [$($wgen)*] [$case] $ty {
$($(#[$req])? $($key =>)? $field $(as $with)? $(| $alias)*),*
});
};
([$dir:tt] $m:ident [$($rgen:tt)*] [$($wgen:tt)*] [$case:tt] $ty:ty {
$($(#[$req:ident])? $($key:literal =>)? $field:ident $(as $with:ty)? $(| $alias:literal)*),* $(,)?
}) => {
$crate::__case_check!($case);
$crate::__keys_impl!([$($wgen)*] [$case] [all] [$dir] $ty {
$($(#[$req])? $($key =>)? $field $(as $with)? $(| $alias)*),*
});
$crate::$m!([$($rgen)*] [$($wgen)*] [$case] $ty {
$($(#[$req])? $($key =>)? $field $(as $with)? $(| $alias)*),*
});
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __both_impls {
([$($rgen:tt)*] [$($wgen:tt)*] [$case:tt] $ty:ty { $($body:tt)* }) => {
$crate::__json_impls!([$($rgen)*] [$($wgen)*] [$case] $ty { $($body)* });
$crate::__beve_impls!([$($rgen)*] [$($wgen)*] [$case] $ty { $($body)* });
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __both_write_impls {
([$($rgen:tt)*] [$($wgen:tt)*] [$case:tt] $ty:ty { $($body:tt)* }) => {
$crate::__json_write_impls!([$($rgen)*] [$($wgen)*] [$case] $ty { $($body)* });
$crate::__beve_write_impls!([$($rgen)*] [$($wgen)*] [$case] $ty { $($body)* });
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __each_name_once {
($($name:ident),* $(,)?) => {
const _: () = {
$( #[allow(dead_code, non_upper_case_globals)] const $name: () = (); )*
};
};
($($index:tt),* $(,)?) => {
const _: () = {
const AT: &[usize] = &[$($index),*];
let mut i = 0;
while i < AT.len() {
let mut j = i + 1;
while j < AT.len() {
::core::assert!(
AT[i] != AT[j],
"structio: this positional declaration names the same field twice, \
so one field would go out in two places and another not at all."
);
j += 1;
}
i += 1;
}
};
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __declares_every_field {
([$($wgen:tt)*] [partial] $ty:ty { $($field:tt),* }) => {};
([$($wgen:tt)*] [all] $ty:ty { $($field:tt),* }) => {
const _: () = {
#[allow(dead_code)]
trait DeclaresEveryField: ::core::marker::Sized {
fn declared() -> Self;
}
impl<$($wgen)*> DeclaresEveryField for $ty {
#[allow(unreachable_code, clippy::empty_loop)]
fn declared() -> Self {
Self { $($field: loop {}),* }
}
}
};
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __is_required {
() => {
false
};
(required) => {
true
};
($other:ident) => {
::core::compile_error!(::core::concat!(
"unrecognized field marker `#[",
::core::stringify!($other),
"]`; the only one is `#[required]`"
))
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __counts_one {
($t:tt) => {
1usize
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __alias_direction {
([write] key $alias:literal) => {
::core::compile_error!(
"an alias is a rule about reading: it is a further key a document \
may use for this field, and the key the field is written under is \
the declared one. A type declared `write_only` is never read, so \
nothing would ever look this one up"
)
};
([write] name $alias:literal) => {
::core::compile_error!(
"an alias is a rule about reading: it is a further name a document \
may use for this variant, and the name the variant is written \
under is the declared one. A type declared `write_only` is never \
read, so nothing would ever look this one up"
)
};
([$dir:tt] $what:ident $alias:literal) => {};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __keys_impl {
(
[$($wgen:tt)*] [$case:tt] [$mode:ident] [$dir:tt] $ty:ty {
$($(#[$req:ident])? $($key:literal =>)? $field:ident $(as $with:ty)? $(| $alias:literal)*),* $(,)?
}
) => {
$crate::__each_name_once!($($field),*);
$crate::__declares_every_field!([$($wgen)*] [$mode] $ty { $($field),* });
impl<$($wgen)*> $crate::Keys for $ty {
const KEYS: &'static [&'static str] = &[
$( $crate::__json_key!([$case] $($key)? [$field]), )*
$( $( $alias, )* )*
];
#[allow(unused_assignments, unused_mut)]
const ALIASES: &'static [u8] = &{
let mut of = [0u8; 0 $( $( + $crate::__counts_one!($alias) )* )*];
let mut j = 0usize;
let mut f = 0usize;
$(
$(
assert!(
f <= u8::MAX as usize,
"an aliased field must be one of the first 256 \
declared: the field an alias fills is a u8"
);
of[j] = f as u8;
j += 1;
$crate::__alias_direction!([$dir] key $alias);
)*
f += 1;
)*
of
};
const MAP: &'static $crate::KeyMap = &$crate::KeyMap::build(Self::KEYS);
#[allow(unused_assignments, unused_mut)]
const REQUIRED: u64 = {
let mut mask = 0u64;
let mut i = 0u32;
$(
$crate::__required_direction!([$dir] $($req)?);
if $crate::__is_required!($($req)?) {
assert!(
i < 64,
"a #[required] field must be one of the first 64 \
declared: the mask that tracks them is a u64"
);
mask |= 1u64 << i;
}
i += 1;
)*
mask
};
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __required_direction {
([write] required) => {
::core::compile_error!(
"`#[required]` is a rule about reading: a document that leaves \
this member out is `MissingKey`. A type declared `write_only` is \
never read, so there is nothing to require"
)
};
([$dir:tt] $($marker:ident)?) => {};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __json_impls {
(
[$de:lifetime $($rgen:tt)*] [$($wgen:tt)*] [$case:tt] $ty:ty {
$($(#[$req:ident])? $($key:literal =>)? $field:ident $(as $with:ty)? $(| $alias:literal)*),* $(,)?
}
) => {
$crate::__json_read_impls!([$de $($rgen)*] [$($wgen)*] [$case] $ty {
$($(#[$req])? $($key =>)? $field $(as $with)? $(| $alias)*),*
});
$crate::__json_write_impls!([$de $($rgen)*] [$($wgen)*] [$case] $ty {
$($(#[$req])? $($key =>)? $field $(as $with)? $(| $alias)*),*
});
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __json_read_impls {
(
[$de:lifetime $($rgen:tt)*] [$($wgen:tt)*] [$case:tt] $ty:ty {
$($(#[$req:ident])? $($key:literal =>)? $field:ident $(as $with:ty)? $(| $alias:literal)*),* $(,)?
}
) => {
impl<$de $($rgen)*> $crate::json::ReadObject<$de> for $ty {
#[inline]
#[allow(unused_assignments, unused_variables, unused_mut)]
fn read_field<O: $crate::Options>(
&mut self,
index: usize,
p: &mut $crate::json::Parser<$de, O>,
) -> ::core::result::Result<bool, $crate::ErrorCode> {
let mut i = 0usize;
$(
if index == i {
if !(p.match_key($crate::__json_key!([$case] $($key)? [$field]))
$( || p.match_key($alias) )*)
{
return ::core::result::Result::Ok(false);
}
p.colon()?;
$crate::__json_read_as!(&mut self.$field, p $(, $with)?)?;
return ::core::result::Result::Ok(true);
}
i += 1;
)*
::core::result::Result::Ok(false)
}
}
impl<$de $($rgen)*> $crate::json::Read<$de> for $ty {
#[inline]
fn read<O: $crate::Options>(
&mut self,
p: &mut $crate::json::Parser<$de, O>,
) -> ::core::result::Result<(), $crate::ErrorCode> {
p.read_object(self)
}
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __json_write_impls {
(
[$($rgen:tt)*] [$($wgen:tt)*] [$case:tt] $ty:ty {
$($(#[$req:ident])? $($key:literal =>)? $field:ident $(as $with:ty)? $(| $alias:literal)*),* $(,)?
}
) => {
impl<$($wgen)*> $crate::json::WriteObject for $ty {
#[inline]
fn write_fields<O: $crate::Options>(
&self,
w: &mut $crate::json::Writer<'_, O>,
) {
const {
let _ = <Self as $crate::Keys>::MAP;
};
$( $crate::__write_member!(
w,
$crate::__json_member!([$case] $($key)? [$field]),
&self.$field
$(, $with)?
); )*
}
}
impl<$($wgen)*> $crate::json::Write for $ty {
#[inline]
fn write<O: $crate::Options>(&self, w: &mut $crate::json::Writer<'_, O>) {
w.write_object(self);
}
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __beve_impls {
(
[$de:lifetime $($rgen:tt)*] [$($wgen:tt)*] [$case:tt] $ty:ty {
$($(#[$req:ident])? $($key:literal =>)? $field:ident $(as $with:ty)? $(| $alias:literal)*),* $(,)?
}
) => {
$crate::__beve_read_impls!([$de $($rgen)*] [$($wgen)*] [$case] $ty {
$($(#[$req])? $($key =>)? $field $(as $with)? $(| $alias)*),*
});
$crate::__beve_write_impls!([$de $($rgen)*] [$($wgen)*] [$case] $ty {
$($(#[$req])? $($key =>)? $field $(as $with)? $(| $alias)*),*
});
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __beve_read_impls {
(
[$de:lifetime $($rgen:tt)*] [$($wgen:tt)*] [$case:tt] $ty:ty {
$($(#[$req:ident])? $($key:literal =>)? $field:ident $(as $with:ty)? $(| $alias:literal)*),* $(,)?
}
) => {
impl<$de $($rgen)*> $crate::beve::ReadObject<$de> for $ty {
#[inline]
#[allow(unused_assignments, unused_variables, unused_mut)]
fn read_field<O: $crate::Options>(
&mut self,
index: usize,
key: &[u8],
r: &mut $crate::beve::Reader<$de, O>,
) -> ::core::result::Result<bool, $crate::ErrorCode> {
let mut i = 0usize;
$(
if index == i {
if !(key == $crate::__json_key!([$case] $($key)? [$field]).as_bytes()
$( || key == $alias.as_bytes() )*)
{
return ::core::result::Result::Ok(false);
}
$crate::__beve_read_as!(&mut self.$field, r $(, $with)?)?;
return ::core::result::Result::Ok(true);
}
i += 1;
)*
::core::result::Result::Ok(false)
}
}
impl<$de $($rgen)*> $crate::beve::Read<$de> for $ty {
#[inline]
fn read<O: $crate::Options>(
&mut self,
r: &mut $crate::beve::Reader<$de, O>,
) -> ::core::result::Result<(), $crate::ErrorCode> {
r.read_object(self)
}
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __beve_write_impls {
(
[$($rgen:tt)*] [$($wgen:tt)*] [$case:tt] $ty:ty {
$($(#[$req:ident])? $($key:literal =>)? $field:ident $(as $with:ty)? $(| $alias:literal)*),* $(,)?
}
) => {
impl<$($wgen)*> $crate::beve::WriteObject for $ty {
#[inline]
fn write_fields<O: $crate::Options>(
&self,
w: &mut $crate::beve::Writer<'_, O>,
) {
const {
let _ = <Self as $crate::Keys>::MAP;
};
$( $crate::__write_member!(
w,
$crate::__beve_key_bytes!($crate::__json_key!([$case] $($key)? [$field])),
&self.$field
$(, $with)?
); )*
}
#[inline]
#[allow(unused_mut)]
fn count_fields<O: $crate::Options>(&self) -> usize {
let mut n = 0usize;
$(
n += !(O::SKIP_NULL
&& $crate::__beve_is_null_as!(&self.$field $(, $with)?)) as usize;
)*
n
}
}
impl<$($wgen)*> $crate::beve::Write for $ty {
#[inline]
fn write<O: $crate::Options>(&self, w: &mut $crate::beve::Writer<'_, O>) {
w.write_object(self);
}
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __json_key {
([$case:tt] $key:literal [$field:ident]) => {
$key
};
([_] [$field:ident]) => {
$crate::case::unraw(::core::stringify!($field))
};
([$case:tt] [$field:ident]) => {
$crate::__case_apply!($case, $crate::case::unraw(::core::stringify!($field)))
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __json_member {
($($key:tt)*) => {{
const KEY: &str = $crate::__json_key!($($key)*);
const N: usize = KEY.len() + 3;
const PREFIX: [u8; N] = $crate::json::quoted_key::<{ N }>(KEY);
const OUT: &str = $crate::case::as_str(&PREFIX);
OUT
}};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __beve_key_bytes {
($key:expr) => {{
const KEY: &str = $key;
const N: usize = $crate::beve::header::key_len(KEY);
const ENCODED: [u8; N] = $crate::beve::header::encode_key::<{ N }>(KEY);
&ENCODED
}};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __case_apply {
($case:literal, $name:expr) => {{
const NAME: &str = $name;
const RULE: &str = $case;
const STYLE: $crate::case::Style = $crate::case::style(RULE);
const N: usize = $crate::case::cased_len(NAME, STYLE);
const CASED: [u8; N] = $crate::case::cased::<{ N }>(NAME, STYLE);
const OUT: &str = $crate::case::as_str(&CASED);
OUT
}};
($other:tt, $name:expr) => {
$name
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __case_check {
(_) => {};
($case:literal) => {};
($other:tt) => {
::core::compile_error!(::core::concat!(
"structio: `",
::core::stringify!($other),
"` is not a case rule; a rule is written as a string, as in \
`object!(Root as \"camelCase\" { .. })`"
));
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __json_read_as {
($place:expr, $p:ident, $with:ty) => {
<$with as $crate::json::ReadAs<'_, _>>::read($place, $p)
};
($place:expr, $p:ident) => {
$crate::json::Read::read($place, $p)
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __write_member {
($w:ident, $key:expr, $place:expr, $with:ty) => {
$w.member_with::<$with, _>($key, $place)
};
($w:ident, $key:expr, $place:expr) => {
$w.member($key, $place)
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __json_write_as {
($place:expr, $w:ident, $with:ty) => {
<$with as $crate::json::WriteAs<_>>::write($place, $w)
};
($place:expr, $w:ident) => {
$crate::json::Write::write($place, $w)
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __json_is_null_as {
($place:expr, $with:ty) => {
<$with as $crate::json::WriteAs<_>>::is_null($place)
};
($place:expr) => {
$crate::json::Write::is_null($place)
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __beve_read_as {
($place:expr, $r:ident, $with:ty) => {
<$with as $crate::beve::ReadAs<'_, _>>::read($place, $r)
};
($place:expr, $r:ident) => {
$crate::beve::Read::read($place, $r)
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __beve_write_as {
($place:expr, $w:ident, $with:ty) => {
<$with as $crate::beve::WriteAs<_>>::write($place, $w)
};
($place:expr, $w:ident) => {
$crate::beve::Write::write($place, $w)
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __beve_is_null_as {
($place:expr, $with:ty) => {
<$with as $crate::beve::WriteAs<_>>::is_null($place)
};
($place:expr) => {
$crate::beve::Write::is_null($place)
};
}
#[macro_export]
macro_rules! array {
(write_only :: $($t:tt)*) => { $crate::__write_only_is_the_marker!(); };
(read_only $($t:tt)*) => { $crate::__no_read_only!(); };
(write_only $($t:tt)*) => { $crate::__declare_array!(__both_write_array_impls $($t)*); };
($($t:tt)*) => { $crate::__declare_array!(__both_array_impls $($t)*); };
}
#[macro_export]
macro_rules! json_array {
(write_only :: $($t:tt)*) => { $crate::__write_only_is_the_marker!(); };
(read_only $($t:tt)*) => { $crate::__no_read_only!(); };
(write_only $($t:tt)*) => { $crate::__declare_array!(__json_write_array_impls $($t)*); };
($($t:tt)*) => { $crate::__declare_array!(__json_array_impls $($t)*); };
}
#[macro_export]
macro_rules! beve_array {
(write_only :: $($t:tt)*) => { $crate::__write_only_is_the_marker!(); };
(read_only $($t:tt)*) => { $crate::__no_read_only!(); };
(write_only $($t:tt)*) => { $crate::__declare_array!(__beve_write_array_impls $($t)*); };
($($t:tt)*) => { $crate::__declare_array!(__beve_array_impls $($t)*); };
}
#[macro_export]
macro_rules! transparent {
(write_only :: $($t:tt)*) => { $crate::__write_only_is_the_marker!(); };
(read_only $($t:tt)*) => { $crate::__no_read_only!(); };
(write_only $($t:tt)*) => {
$crate::__declare_transparent!([write] __both_write_transparent_impls $($t)*);
};
($($t:tt)*) => {
$crate::__declare_transparent!([both] __both_transparent_impls $($t)*);
};
}
#[macro_export]
macro_rules! json_transparent {
(write_only :: $($t:tt)*) => { $crate::__write_only_is_the_marker!(); };
(read_only $($t:tt)*) => { $crate::__no_read_only!(); };
(write_only $($t:tt)*) => {
$crate::__declare_transparent!([write] __json_write_transparent_impls $($t)*);
};
($($t:tt)*) => {
$crate::__declare_transparent!([both] __json_transparent_impls $($t)*);
};
}
#[macro_export]
macro_rules! beve_transparent {
(write_only :: $($t:tt)*) => { $crate::__write_only_is_the_marker!(); };
(read_only $($t:tt)*) => { $crate::__no_read_only!(); };
(write_only $($t:tt)*) => {
$crate::__declare_transparent!([write] __beve_write_transparent_impls $($t)*);
};
($($t:tt)*) => {
$crate::__declare_transparent!([both] __beve_transparent_impls $($t)*);
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __declare_transparent {
([$dir:tt] $m:ident $name:ident ( $($rest:tt)* )) => {
::core::compile_error!(
"structio: the field goes in braces, not in the parentheses the \
struct is written with: `transparent!(UserId { 0 })`. A tuple \
struct's field is named by its position here, as it is in \
`array!`"
);
};
([$dir:tt] $m:ident [ $de:lifetime $($gen:tt)* ] $ty:ty { $field:tt $(as $with:ty)? }) => {
$crate::__declares_every_field!([$de $($gen)*] [all] $ty { $field });
$crate::$m!([$de $($gen)*] [$de $($gen)*] $ty { $field $(as $with)? });
};
([$dir:tt] $m:ident [ $($gen:tt)* ] $ty:ty { $field:tt $(as $with:ty)? }) => {
$crate::__declares_every_field!([$($gen)*] [all] $ty { $field });
$crate::$m!(['de, $($gen)*] [$($gen)*] $ty { $field $(as $with)? });
};
([$dir:tt] $m:ident $ty:ty { $field:tt $(as $with:ty)? }) => {
$crate::__declares_every_field!([] [all] $ty { $field });
$crate::$m!(['de] [] $ty { $field $(as $with)? });
};
([$dir:tt] $m:ident $($rest:tt)*) => {
::core::compile_error!(
"structio: a transparent declaration is a type and the one field \
it is written as, in braces: `transparent!(UserId { 0 })` for a \
tuple struct, `transparent!(Meters { value })` for a named one, \
with an adapter as `{ 0 as Millis }` and generics in a leading \
bracketed list"
);
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __both_transparent_impls {
([$($rgen:tt)*] [$($wgen:tt)*] $ty:ty { $($body:tt)* }) => {
$crate::__json_transparent_impls!([$($rgen)*] [$($wgen)*] $ty { $($body)* });
$crate::__beve_transparent_impls!([$($rgen)*] [$($wgen)*] $ty { $($body)* });
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __both_write_transparent_impls {
([$($rgen:tt)*] [$($wgen:tt)*] $ty:ty { $($body:tt)* }) => {
$crate::__json_write_transparent_impls!([$($rgen)*] [$($wgen)*] $ty { $($body)* });
$crate::__beve_write_transparent_impls!([$($rgen)*] [$($wgen)*] $ty { $($body)* });
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __json_transparent_impls {
([$($rgen:tt)*] [$($wgen:tt)*] $ty:ty { $($body:tt)* }) => {
$crate::__json_read_transparent_impls!([$($rgen)*] [$($wgen)*] $ty { $($body)* });
$crate::__json_write_transparent_impls!([$($rgen)*] [$($wgen)*] $ty { $($body)* });
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __json_read_transparent_impls {
([$de:lifetime $($rgen:tt)*] [$($wgen:tt)*] $ty:ty { $field:tt $(as $with:ty)? }) => {
impl<$de $($rgen)*> $crate::json::Read<$de> for $ty {
#[inline(always)]
fn read<O: $crate::Options>(
&mut self,
p: &mut $crate::json::Parser<$de, O>,
) -> ::core::result::Result<(), $crate::ErrorCode> {
$crate::__json_read_as!(&mut self.$field, p $(, $with)?)
}
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __json_write_transparent_impls {
([$($rgen:tt)*] [$($wgen:tt)*] $ty:ty { $field:tt $(as $with:ty)? }) => {
impl<$($wgen)*> $crate::json::Write for $ty {
#[inline(always)]
fn write<O: $crate::Options>(&self, w: &mut $crate::json::Writer<'_, O>) {
$crate::__json_write_as!(&self.$field, w $(, $with)?);
}
#[inline(always)]
fn is_null(&self) -> bool {
$crate::__json_is_null_as!(&self.$field $(, $with)?)
}
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __beve_transparent_impls {
([$($rgen:tt)*] [$($wgen:tt)*] $ty:ty { $($body:tt)* }) => {
$crate::__beve_read_transparent_impls!([$($rgen)*] [$($wgen)*] $ty { $($body)* });
$crate::__beve_write_transparent_impls!([$($rgen)*] [$($wgen)*] $ty { $($body)* });
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __beve_read_transparent_impls {
([$de:lifetime $($rgen:tt)*] [$($wgen:tt)*] $ty:ty { $field:tt $(as $with:ty)? }) => {
impl<$de $($rgen)*> $crate::beve::Read<$de> for $ty {
#[inline(always)]
fn read<O: $crate::Options>(
&mut self,
r: &mut $crate::beve::Reader<$de, O>,
) -> ::core::result::Result<(), $crate::ErrorCode> {
$crate::__beve_read_as!(&mut self.$field, r $(, $with)?)
}
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __beve_write_transparent_impls {
([$($rgen:tt)*] [$($wgen:tt)*] $ty:ty { $field:tt $(as $with:ty)? }) => {
impl<$($wgen)*> $crate::beve::Write for $ty {
#[inline(always)]
fn write<O: $crate::Options>(&self, w: &mut $crate::beve::Writer<'_, O>) {
$crate::__beve_write_as!(&self.$field, w $(, $with)?);
}
#[inline(always)]
fn is_null(&self) -> bool {
$crate::__beve_is_null_as!(&self.$field $(, $with)?)
}
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __declare_array {
($m:ident [ $de:lifetime $($gen:tt)* ] $ty:ty as $case:tt [ $($body:tt)* ]) => {
$crate::__no_array_case!();
};
($m:ident [ $de:lifetime $($gen:tt)* ] $ty:ty [ $($body:tt)* ]) => {
$crate::__declared_array!($m [$de $($gen)*] [$de $($gen)*] $ty [ $($body)* ]);
};
($m:ident [ $($gen:tt)* ] $ty:ty as $case:tt [ $($body:tt)* ]) => {
$crate::__no_array_case!();
};
($m:ident [ $($gen:tt)* ] $ty:ty [ $($body:tt)* ]) => {
$crate::__declared_array!($m ['de, $($gen)*] [$($gen)*] $ty [ $($body)* ]);
};
($m:ident $ty:ty as $case:tt [ $($body:tt)* ]) => {
$crate::__no_array_case!();
};
($m:ident $ty:ty [ $($body:tt)* ]) => {
$crate::__declared_array!($m ['de] [] $ty [ $($body)* ]);
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __no_array_case {
() => {
::core::compile_error!(
"structio: a positional struct has no keys, so a case rule has nothing to \
convert. Case rules belong on `object!`, `unit_enum!` and `tagged_enum!`."
);
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __both_array_impls {
([$($rgen:tt)*] [$($wgen:tt)*] $ty:ty [ $($body:tt)* ]) => {
$crate::__json_array_impls!([$($rgen)*] [$($wgen)*] $ty [ $($body)* ]);
$crate::__beve_array_impls!([$($rgen)*] [$($wgen)*] $ty [ $($body)* ]);
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __both_write_array_impls {
([$($rgen:tt)*] [$($wgen:tt)*] $ty:ty [ $($body:tt)* ]) => {
$crate::__json_write_array_impls!([$($rgen)*] [$($wgen)*] $ty [ $($body)* ]);
$crate::__beve_write_array_impls!([$($rgen)*] [$($wgen)*] $ty [ $($body)* ]);
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __declared_array {
($m:ident [$($rgen:tt)*] [$($wgen:tt)*] $ty:ty [ $elem:ty ; $($field:ident ,)* .. ]) => {
$crate::__elements_impl!([$($wgen)*] [partial] $ty [ $elem ; $($field),* ]);
$crate::$m!([$($rgen)*] [$($wgen)*] $ty [ $elem ; $($field),* ]);
};
($m:ident [$($rgen:tt)*] [$($wgen:tt)*] $ty:ty [ $elem:ty ; $($field:ident),* $(,)? ]) => {
$crate::__elements_impl!([$($wgen)*] [all] $ty [ $elem ; $($field),* ]);
$crate::$m!([$($rgen)*] [$($wgen)*] $ty [ $elem ; $($field),* ]);
};
($m:ident [$($rgen:tt)*] [$($wgen:tt)*] $ty:ty [ $($field:ident ,)* .. ]) => {
$crate::__elements_impl!([$($wgen)*] [partial] $ty [ $($field),* ]);
$crate::$m!([$($rgen)*] [$($wgen)*] $ty [ $($field),* ]);
};
($m:ident [$($rgen:tt)*] [$($wgen:tt)*] $ty:ty [ $($field:ident),* $(,)? ]) => {
$crate::__elements_impl!([$($wgen)*] [all] $ty [ $($field),* ]);
$crate::$m!([$($rgen)*] [$($wgen)*] $ty [ $($field),* ]);
};
($m:ident [$($rgen:tt)*] [$($wgen:tt)*] $ty:ty [ $elem:ty ; $($body:tt)* ]) => {
$crate::__array_positions!($m [$($rgen)*] [$($wgen)*] $ty [$elem ;] [] $($body)*);
};
($m:ident [$($rgen:tt)*] [$($wgen:tt)*] $ty:ty [ $($body:tt)* ]) => {
$crate::__array_positions!($m [$($rgen)*] [$($wgen)*] $ty [] [] $($body)*);
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __array_positions {
($m:ident [$($rgen:tt)*] [$($wgen:tt)*] $ty:ty [$($elem:tt)*] [$($acc:tt)*] ..) => {
$crate::__elements_impl!([$($wgen)*] [partial] $ty [ $($elem)* $($acc)* ]);
$crate::$m!([$($rgen)*] [$($wgen)*] $ty [ $($elem)* $($acc)* ]);
};
($m:ident [$($rgen:tt)*] [$($wgen:tt)*] $ty:ty [$($elem:tt)*] [$($acc:tt)*]) => {
$crate::__elements_impl!([$($wgen)*] [all] $ty [ $($elem)* $($acc)* ]);
$crate::$m!([$($rgen)*] [$($wgen)*] $ty [ $($elem)* $($acc)* ]);
};
(
$m:ident [$($rgen:tt)*] [$($wgen:tt)*] $ty:ty [$($elem:tt)*] [$($acc:tt)*]
$field:tt , $($rest:tt)*
) => {
$crate::__array_positions!(
$m [$($rgen)*] [$($wgen)*] $ty [$($elem)*] [$($acc)* $field ,] $($rest)*
);
};
(
$m:ident [$($rgen:tt)*] [$($wgen:tt)*] $ty:ty [$($elem:tt)*] [$($acc:tt)*]
$field:tt
) => {
$crate::__array_positions!(
$m [$($rgen)*] [$($wgen)*] $ty [$($elem)*] [$($acc)* $field]
);
};
(
$m:ident [$($rgen:tt)*] [$($wgen:tt)*] $ty:ty [$($elem:tt)*] [$($acc:tt)*]
$($rest:tt)*
) => {
::core::compile_error!(::core::concat!(
"structio: `",
::core::stringify!($($rest)*),
"` is not a positional field list. A list is a comma-separated run of field \
names, or of tuple indices for a tuple struct, ending in `..` where leaving \
a field out is deliberate."
));
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __elements_impl {
([$($wgen:tt)*] [$mode:ident] $ty:ty [ $elem:ty ; $($field:tt),* $(,)? ]) => {
$crate::__elements_impl!([$($wgen)*] [$mode] $ty [ $($field),* ]);
const _: () = {
#[allow(dead_code)]
fn every_field_is_the_element_type<$($wgen)*>(v: &$ty) {
$( let _: &$elem = &v.$field; )*
}
};
};
([$($wgen:tt)*] [$mode:ident] $ty:ty [ $($field:tt),* $(,)? ]) => {
$crate::__each_name_once!($($field),*);
$crate::__declares_every_field!([$($wgen)*] [$mode] $ty { $($field),* });
impl<$($wgen)*> $crate::Elements for $ty {
const LEN: usize =
<[&'static str]>::len(&[$( ::core::stringify!($field) ),*]);
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __json_array_impls {
([$($rgen:tt)*] [$($wgen:tt)*] $ty:ty [ $elem:ty ; $($field:tt),* $(,)? ]) => {
$crate::__json_array_impls!([$($rgen)*] [$($wgen)*] $ty [ $($field),* ]);
};
([$de:lifetime $($rgen:tt)*] [$($wgen:tt)*] $ty:ty [ $($field:tt),* $(,)? ]) => {
$crate::__json_read_array_impls!([$de $($rgen)*] [$($wgen)*] $ty [ $($field),* ]);
$crate::__json_write_array_impls!([$de $($rgen)*] [$($wgen)*] $ty [ $($field),* ]);
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __json_read_array_impls {
([$de:lifetime $($rgen:tt)*] [$($wgen:tt)*] $ty:ty [ $($field:tt),* $(,)? ]) => {
impl<$de $($rgen)*> $crate::json::ReadArray<$de> for $ty {
#[inline]
#[allow(unused_assignments, unused_variables, unused_mut)]
fn read_element<O: $crate::Options>(
&mut self,
index: usize,
p: &mut $crate::json::Parser<$de, O>,
) -> ::core::result::Result<(), $crate::ErrorCode> {
let mut i = 0usize;
$(
if index == i {
return $crate::json::Read::read(&mut self.$field, p);
}
i += 1;
)*
::core::result::Result::Err($crate::ErrorCode::ArrayLengthMismatch)
}
}
impl<$de $($rgen)*> $crate::json::Read<$de> for $ty {
#[inline]
fn read<O: $crate::Options>(
&mut self,
p: &mut $crate::json::Parser<$de, O>,
) -> ::core::result::Result<(), $crate::ErrorCode> {
p.read_array(self)
}
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __json_write_array_impls {
([$($rgen:tt)*] [$($wgen:tt)*] $ty:ty [ $elem:ty ; $($field:tt),* $(,)? ]) => {
$crate::__json_write_array_impls!([$($rgen)*] [$($wgen)*] $ty [ $($field),* ]);
};
([$($rgen:tt)*] [$($wgen:tt)*] $ty:ty [ $($field:tt),* $(,)? ]) => {
impl<$($wgen)*> $crate::json::WriteArray for $ty {
#[inline]
fn write_elements<O: $crate::Options>(
&self,
w: &mut $crate::json::Writer<'_, O>,
) {
$( w.element(&self.$field); )*
}
}
impl<$($wgen)*> $crate::json::Write for $ty {
#[inline]
fn write<O: $crate::Options>(&self, w: &mut $crate::json::Writer<'_, O>) {
w.write_array(self);
}
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __beve_array_impls {
([$($rgen:tt)*] [$($wgen:tt)*] $ty:ty [ $($body:tt)* ]) => {
$crate::__beve_read_array_impls!([$($rgen)*] [$($wgen)*] $ty [ $($body)* ]);
$crate::__beve_write_array_impls!([$($rgen)*] [$($wgen)*] $ty [ $($body)* ]);
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __beve_read_array_impls {
([$($rgen:tt)*] [$($wgen:tt)*] $ty:ty [ $elem:ty ; $($field:tt),* $(,)? ]) => {
$crate::__beve_read_array_impls!([$($rgen)*] [$($wgen)*] $ty [ $($field),* ]);
};
([$de:lifetime $($rgen:tt)*] [$($wgen:tt)*] $ty:ty [ $($field:tt),* $(,)? ]) => {
impl<$de $($rgen)*> $crate::beve::ReadArray<$de> for $ty {
#[inline]
#[allow(unused_assignments, unused_variables, unused_mut)]
fn read_element<O: $crate::Options>(
&mut self,
index: usize,
r: &mut $crate::beve::Reader<$de, O>,
) -> ::core::result::Result<(), $crate::ErrorCode> {
let mut i = 0usize;
$(
if index == i {
return $crate::beve::Read::read(&mut self.$field, r);
}
i += 1;
)*
::core::result::Result::Err($crate::ErrorCode::ArrayLengthMismatch)
}
}
impl<$de $($rgen)*> $crate::beve::Read<$de> for $ty {
#[inline]
fn read<O: $crate::Options>(
&mut self,
r: &mut $crate::beve::Reader<$de, O>,
) -> ::core::result::Result<(), $crate::ErrorCode> {
r.read_array(self)
}
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __beve_write_array_impls {
([$($rgen:tt)*] [$($wgen:tt)*] $ty:ty [ $elem:ty ; $($field:tt),* $(,)? ]) => {
$crate::__beve_write_array_body!([$($rgen)*] [$($wgen)*] $ty [ $($field),* ] {
const ARRAY: ::core::option::Option<&'static [u8]> =
<$elem as $crate::beve::Write>::ARRAY;
#[inline]
fn write_payload<O: $crate::Options>(
&self,
w: &mut $crate::beve::Writer<'_, O>,
) {
<$elem as $crate::beve::Write>::write_payload(&[$( self.$field ),*], w);
}
});
};
([$($rgen:tt)*] [$($wgen:tt)*] $ty:ty [ $($field:tt),* $(,)? ]) => {
$crate::__beve_write_array_body!([$($rgen)*] [$($wgen)*] $ty [ $($field),* ] {});
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __beve_write_array_body {
(
[$($rgen:tt)*] [$($wgen:tt)*] $ty:ty [ $($field:tt),* ] { $($typed:tt)* }
) => {
impl<$($wgen)*> $crate::beve::WriteArray for $ty {
#[inline]
fn write_elements<O: $crate::Options>(
&self,
w: &mut $crate::beve::Writer<'_, O>,
) {
$( w.element(&self.$field); )*
}
$($typed)*
}
impl<$($wgen)*> $crate::beve::Write for $ty {
#[inline]
fn write<O: $crate::Options>(&self, w: &mut $crate::beve::Writer<'_, O>) {
w.write_array(self);
}
}
};
}
#[macro_export]
macro_rules! unit_enum {
(write_only :: $($t:tt)*) => { $crate::__write_only_is_the_marker!(); };
(read_only $($t:tt)*) => { $crate::__no_read_only!(); };
(write_only $($t:tt)*) => { $crate::__unit_enum!([write] __both_write_unit_enum_impls $($t)*); };
($($t:tt)*) => { $crate::__unit_enum!([both] __both_unit_enum_impls $($t)*); };
}
#[doc(hidden)]
#[macro_export]
macro_rules! __unit_enum {
([$dir:tt] $m:ident [$($gen:tt)*] $ty:ty as $case:tt { $($($name:literal =>)? $variant:ident $(| $valias:literal)*),* $(,)? }) => {
$crate::__declare_enum!(
[$dir] $m [$($gen)*] $ty as $case { $($($name =>)? $variant $(| $valias)*),* }
);
};
([$dir:tt] $m:ident [$($gen:tt)*] $ty:ty { $($($name:literal =>)? $variant:ident $(| $valias:literal)*),* $(,)? }) => {
$crate::__declare_enum!(
[$dir] $m [$($gen)*] $ty { $($($name =>)? $variant $(| $valias)*),* }
);
};
([$dir:tt] $m:ident $ty:ty as $case:tt { $($($name:literal =>)? $variant:ident $(| $valias:literal)*),* $(,)? }) => {
$crate::__declare_enum!(
[$dir] $m $ty as $case { $($($name =>)? $variant $(| $valias)*),* }
);
};
([$dir:tt] $m:ident $ty:ty { $($($name:literal =>)? $variant:ident $(| $valias:literal)*),* $(,)? }) => {
$crate::__declare_enum!(
[$dir] $m $ty { $($($name =>)? $variant $(| $valias)*),* }
);
};
([$dir:tt] $m:ident $($rest:tt)*) => {
::core::compile_error!(
"`unit_enum!` takes a type and a brace-delimited list of variant \
names, each optionally renamed with `\"name\" => Variant` and \
aliased with `Variant | \"other\"`. A variant that carries a \
value, written `Variant(_)`, belongs to `tagged_enum!` instead, \
and so does a tag clause: a unit enum's value is a bare name, \
with no object for a tag to go in."
);
};
}
#[macro_export]
macro_rules! tagged_enum {
(write_only :: $($t:tt)*) => { $crate::__write_only_is_the_marker!(); };
(read_only $($t:tt)*) => { $crate::__no_read_only!(); };
(write_only $($t:tt)*) => { $crate::__declare_enum!([write] __both_write_enum_impls $($t)*); };
($($t:tt)*) => { $crate::__declare_enum!([both] __both_enum_impls $($t)*); };
}
#[macro_export]
macro_rules! json_tagged_enum {
(write_only :: $($t:tt)*) => { $crate::__write_only_is_the_marker!(); };
(read_only $($t:tt)*) => { $crate::__no_read_only!(); };
(write_only $($t:tt)*) => { $crate::__declare_enum!([write] __json_write_enum_impls $($t)*); };
($($t:tt)*) => { $crate::__declare_enum!([both] __json_enum_impls $($t)*); };
}
#[macro_export]
macro_rules! beve_tagged_enum {
(write_only :: $($t:tt)*) => { $crate::__write_only_is_the_marker!(); };
(read_only $($t:tt)*) => { $crate::__no_read_only!(); };
(write_only $($t:tt)*) => { $crate::__declare_enum!([write] __beve_write_enum_impls $($t)*); };
($($t:tt)*) => { $crate::__declare_enum!([both] __beve_enum_impls $($t)*); };
}
#[doc(hidden)]
#[macro_export]
macro_rules! __declare_enum {
([$dir:tt] $m:ident [ $de:lifetime $($gen:tt)* ] $ty:ty as tag $tag:literal { $($body:tt)* }) => {
$crate::__declared_enum!(
[$dir] $m [$de $($gen)*] [$de $($gen)*] [_] [$tag] $ty { $($body)* });
};
([$dir:tt] $m:ident [ $de:lifetime $($gen:tt)* ] $ty:ty as $case:tt tag $tag:literal { $($body:tt)* }) => {
$crate::__declared_enum!(
[$dir] $m [$de $($gen)*] [$de $($gen)*] [$case] [$tag] $ty { $($body)* });
};
([$dir:tt] $m:ident [ $de:lifetime $($gen:tt)* ] $ty:ty as $case:tt { $($body:tt)* }) => {
$crate::__declared_enum!([$dir] $m [$de $($gen)*] [$de $($gen)*] [$case] [] $ty { $($body)* });
};
([$dir:tt] $m:ident [ $de:lifetime $($gen:tt)* ] $ty:ty { $($body:tt)* }) => {
$crate::__declared_enum!([$dir] $m [$de $($gen)*] [$de $($gen)*] [_] [] $ty { $($body)* });
};
([$dir:tt] $m:ident [ $($gen:tt)* ] $ty:ty as tag $tag:literal { $($body:tt)* }) => {
$crate::__declared_enum!([$dir] $m ['de, $($gen)*] [$($gen)*] [_] [$tag] $ty { $($body)* });
};
([$dir:tt] $m:ident [ $($gen:tt)* ] $ty:ty as $case:tt tag $tag:literal { $($body:tt)* }) => {
$crate::__declared_enum!(
[$dir] $m ['de, $($gen)*] [$($gen)*] [$case] [$tag] $ty { $($body)* });
};
([$dir:tt] $m:ident [ $($gen:tt)* ] $ty:ty as $case:tt { $($body:tt)* }) => {
$crate::__declared_enum!([$dir] $m ['de, $($gen)*] [$($gen)*] [$case] [] $ty { $($body)* });
};
([$dir:tt] $m:ident [ $($gen:tt)* ] $ty:ty { $($body:tt)* }) => {
$crate::__declared_enum!([$dir] $m ['de, $($gen)*] [$($gen)*] [_] [] $ty { $($body)* });
};
([$dir:tt] $m:ident $ty:ty as tag $tag:literal { $($body:tt)* }) => {
$crate::__declared_enum!([$dir] $m ['de] [] [_] [$tag] $ty { $($body)* });
};
([$dir:tt] $m:ident $ty:ty as $case:tt tag $tag:literal { $($body:tt)* }) => {
$crate::__declared_enum!([$dir] $m ['de] [] [$case] [$tag] $ty { $($body)* });
};
([$dir:tt] $m:ident $ty:ty as $case:tt { $($body:tt)* }) => {
$crate::__declared_enum!([$dir] $m ['de] [] [$case] [] $ty { $($body)* });
};
([$dir:tt] $m:ident $ty:ty { $($body:tt)* }) => {
$crate::__declared_enum!([$dir] $m ['de] [] [_] [] $ty { $($body)* });
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __declared_enum {
(
[$dir:tt] $m:ident [$($rgen:tt)*] [$($wgen:tt)*] [$case:tt] [] $ty:ty {
$($body:tt)*
}
) => {
$crate::__case_check!($case);
$crate::__variants_impl!([$($wgen)*] [$case] [$dir] $ty { $($body)* });
$crate::$m!([$($rgen)*] [$($wgen)*] [$case] [] $ty { $($body)* });
};
(
[$dir:tt] $m:ident [$($rgen:tt)*] [$($wgen:tt)*] [$case:tt] [$tag:literal] $ty:ty {
$($body:tt)*
}
) => {
$crate::__case_check!($case);
$crate::__variants_impl!([$($wgen)*] [$case] [$dir] $ty { $($body)* });
$crate::__tag_check!([$($wgen)*] [$tag] $ty { $($body)* });
$crate::$m!([$($rgen)*] [$($wgen)*] [$case] [$tag] $ty { $($body)* });
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __both_unit_enum_impls {
([$($rgen:tt)*] [$($wgen:tt)*] [$case:tt] [] $ty:ty { $($body:tt)* }) => {
$crate::__json_enum_impls!([$($rgen)*] [$($wgen)*] [$case] [] $ty { $($body)* });
$crate::__beve_unit_enum_impls!([$($rgen)*] [$($wgen)*] [$case] $ty { $($body)* });
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __both_write_unit_enum_impls {
([$($rgen:tt)*] [$($wgen:tt)*] [$case:tt] [] $ty:ty { $($body:tt)* }) => {
$crate::__json_write_enum_impls!([$($rgen)*] [$($wgen)*] [$case] [] $ty { $($body)* });
$crate::__beve_write_unit_enum_impls!([$($rgen)*] [$($wgen)*] [$case] $ty { $($body)* });
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __both_enum_impls {
([$($rgen:tt)*] [$($wgen:tt)*] [$case:tt] [$($tag:literal)?] $ty:ty { $($body:tt)* }) => {
$crate::__json_enum_impls!([$($rgen)*] [$($wgen)*] [$case] [$($tag)?] $ty { $($body)* });
$crate::__beve_enum_impls!([$($rgen)*] [$($wgen)*] [$case] [$($tag)?] $ty { $($body)* });
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __both_write_enum_impls {
([$($rgen:tt)*] [$($wgen:tt)*] [$case:tt] [$($tag:literal)?] $ty:ty { $($body:tt)* }) => {
$crate::__json_write_enum_impls!(
[$($rgen)*] [$($wgen)*] [$case] [$($tag)?] $ty { $($body)* });
$crate::__beve_write_enum_impls!(
[$($rgen)*] [$($wgen)*] [$case] [$($tag)?] $ty { $($body)* });
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __tag_check {
(
[] [$tag:literal] $ty:ty {
$($($name:literal =>)? $variant:ident $(($($payload:tt)*))? $(| $valias:literal)*),* $(,)?
}
) => {
$( $crate::__tag_check_one!([$tag] $ty, $variant $(($($payload)*))?); )*
};
([$($wgen:tt)+] [$tag:literal] $ty:ty { $($body:tt)* }) => {};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __tag_check_one {
([$tag:literal] $ty:ty, $variant:ident) => {};
([$tag:literal] $ty:ty, $variant:ident ($($payload:tt)*)) => {
const _: () = $crate::assert_tag_not_a_field($tag, <$ty>::$variant);
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __tag_check_generic {
([] [$tag:literal] { $($body:tt)* }) => {};
(
[$($wgen:tt)+] [$tag:literal] {
$($($name:literal =>)? $variant:ident $(($($payload:tt)*))? $(| $valias:literal)*),* $(,)?
}
) => {
$( $crate::__tag_check_generic_one!([$tag] $variant $(($($payload)*))?); )*
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __tag_check_generic_one {
([$tag:literal] $variant:ident) => {};
([$tag:literal] $variant:ident ($($payload:tt)*)) => {
$crate::assert_tag_not_a_field($tag, Self::$variant);
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __payload_is_wildcard {
() => {};
(_) => {};
($($other:tt)*) => {
::core::compile_error!(
"structio: a variant payload is written `(_)`, and carries no options of its own. \
Field adapters (`as ...`) are supported on `object!` fields, not on enum payloads."
);
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __variants_impl {
(
[$($wgen:tt)*] [$case:tt] [$dir:tt] $ty:ty {
$($($name:literal =>)? $variant:ident $(($($payload:tt)*))? $(| $valias:literal)*),* $(,)?
}
) => {
$crate::__each_name_once!($($variant),*);
$( $crate::__payload_is_wildcard!($($($payload)*)?); )*
impl<$($wgen)*> $crate::Variants for $ty {
const VARIANTS: &'static [&'static str] = &[
$( $crate::__json_key!([$case] $($name)? [$variant]), )*
$( $( $valias, )* )*
];
#[allow(unused_assignments, unused_mut)]
const ALIASES: &'static [u8] = &{
let mut of = [0u8; 0 $( $( + $crate::__counts_one!($valias) )* )*];
let mut j = 0usize;
let mut v = 0usize;
$(
$(
assert!(
v <= u8::MAX as usize,
"an aliased variant must be one of the first 256 \
declared: the variant an alias names is a u8"
);
of[j] = v as u8;
j += 1;
$crate::__alias_direction!([$dir] name $valias);
)*
v += 1;
)*
of
};
const MAP: &'static $crate::KeyMap = &$crate::KeyMap::build(Self::VARIANTS);
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __json_enum_impls {
($($t:tt)*) => {
$crate::__json_read_enum_impls!($($t)*);
$crate::__json_write_enum_impls!($($t)*);
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __json_read_enum_impls {
(
[$($rgen:tt)*] [$($wgen:tt)*] [$case:tt] [$tag:literal] $ty:ty { $($body:tt)* }
) => {
$crate::__json_read_internal_enum_impls!(
[$($rgen)*] [$($wgen)*] [$case] [$tag] $ty { $($body)* });
};
(
[$de:lifetime $($rgen:tt)*] [$($wgen:tt)*] [$case:tt] [] $ty:ty {
$($($name:literal =>)? $variant:ident $(($($payload:tt)*))? $(| $valias:literal)*),* $(,)?
}
) => {
impl<$de $($rgen)*> $crate::json::ReadEnum<$de> for $ty {
#[inline]
#[allow(unused_assignments, unused_variables, unused_mut)]
fn read_name<O: $crate::Options>(
&mut self,
index: usize,
p: &mut $crate::json::Parser<$de, O>,
) -> ::core::result::Result<bool, $crate::ErrorCode> {
let mut i = 0usize;
$(
if index == i {
return $crate::__json_read_name!(
self, p,
[$crate::__json_key!([$case] $($name)? [$variant]) $(, $valias)*],
$variant $(($($payload)*))?
);
}
i += 1;
)*
::core::result::Result::Ok(false)
}
#[inline]
#[allow(unused_assignments, unused_variables, unused_mut, unreachable_patterns)]
fn read_payload<O: $crate::Options>(
&mut self,
index: usize,
p: &mut $crate::json::Parser<$de, O>,
) -> ::core::result::Result<bool, $crate::ErrorCode> {
let mut i = 0usize;
$(
if index == i {
return $crate::__json_read_payload!(
self, p,
[$crate::__json_key!([$case] $($name)? [$variant]) $(, $valias)*],
$variant $(($($payload)*))?
);
}
i += 1;
)*
::core::result::Result::Ok(false)
}
}
impl<$de $($rgen)*> $crate::json::Read<$de> for $ty {
#[inline]
fn read<O: $crate::Options>(
&mut self,
p: &mut $crate::json::Parser<$de, O>,
) -> ::core::result::Result<(), $crate::ErrorCode> {
p.read_enum(self)
}
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __json_write_enum_impls {
(
[$($rgen:tt)*] [$($wgen:tt)*] [$case:tt] [$tag:literal] $ty:ty { $($body:tt)* }
) => {
$crate::__json_write_internal_enum_impls!(
[$($rgen)*] [$($wgen)*] [$case] [$tag] $ty { $($body)* });
};
(
[$($rgen:tt)*] [$($wgen:tt)*] [$case:tt] [] $ty:ty {
$($($name:literal =>)? $variant:ident $(($($payload:tt)*))? $(| $valias:literal)*),* $(,)?
}
) => {
impl<$($wgen)*> $crate::json::Write for $ty {
#[inline]
#[allow(irrefutable_let_patterns)]
fn write<O: $crate::Options>(&self, w: &mut $crate::json::Writer<'_, O>) {
const {
let _ = <Self as $crate::Variants>::MAP;
};
$(
$crate::__write_variant!(
self, w,
$crate::__json_key!([$case] $($name)? [$variant]),
$crate::__json_member!([$case] $($name)? [$variant]),
$variant $(($($payload)*))?
);
)*
match self { $( Self::$variant { .. } => {} ),* }
}
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __json_read_name {
($self:ident, $p:ident, [$($name:expr),+], $variant:ident) => {
if $( $p.match_key($name) )||+ {
*$self = Self::$variant;
::core::result::Result::Ok(true)
} else {
::core::result::Result::Ok(false)
}
};
($self:ident, $p:ident, [$($name:expr),+], $variant:ident ($($payload:tt)*)) => {
if $( $p.match_key($name) )||+ {
::core::result::Result::Err($crate::ErrorCode::ExpectedBrace)
} else {
::core::result::Result::Ok(false)
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __json_read_payload {
($self:ident, $p:ident, [$($name:expr),+], $variant:ident) => {
if $( $p.match_key($name) )||+ {
$p.colon()?;
if $p.try_null()? {
*$self = Self::$variant;
::core::result::Result::Ok(true)
} else {
::core::result::Result::Err($crate::ErrorCode::ExpectedNull)
}
} else {
::core::result::Result::Ok(false)
}
};
($self:ident, $p:ident, [$($name:expr),+], $variant:ident ($($payload:tt)*)) => {
if $( $p.match_key($name) )||+ {
$p.colon()?;
match $self {
Self::$variant(v) => {
$crate::json::Read::read(v, $p)?;
}
_ => {
let mut value = ::core::default::Default::default();
$crate::json::Read::read(&mut value, $p)?;
*$self = Self::$variant(value);
}
}
::core::result::Result::Ok(true)
} else {
::core::result::Result::Ok(false)
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __json_read_internal_enum_impls {
(
[$de:lifetime $($rgen:tt)*] [$($wgen:tt)*] [$case:tt] [$tag:literal] $ty:ty {
$($($name:literal =>)? $variant:ident $(($($payload:tt)*))? $(| $valias:literal)*),* $(,)?
}
) => {
impl<$de $($rgen)*> $crate::json::ReadInternallyTagged<$de> for $ty {
const TAG: &'static str = $tag;
#[inline]
#[allow(unused_assignments, unused_variables, unused_mut, unreachable_patterns)]
fn read_variant<O: $crate::Options>(
&mut self,
index: usize,
p: &mut $crate::json::Parser<$de, O>,
open: usize,
) -> ::core::result::Result<bool, $crate::ErrorCode> {
let mut i = 0usize;
$(
if index == i {
return $crate::__json_read_internal!(
self, p, open,
[$crate::__json_key!([$case] $($name)? [$variant]) $(, $valias)*],
$variant $(($($payload)*))?
);
}
i += 1;
)*
::core::result::Result::Ok(false)
}
}
impl<$de $($rgen)*> $crate::json::Read<$de> for $ty {
#[inline]
fn read<O: $crate::Options>(
&mut self,
p: &mut $crate::json::Parser<$de, O>,
) -> ::core::result::Result<(), $crate::ErrorCode> {
p.read_internally_tagged(self)
}
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __json_write_internal_enum_impls {
(
[$($rgen:tt)*] [$($wgen:tt)*] [$case:tt] [$tag:literal] $ty:ty {
$($($name:literal =>)? $variant:ident $(($($payload:tt)*))? $(| $valias:literal)*),* $(,)?
}
) => {
impl<$($wgen)*> $crate::json::Write for $ty {
#[inline]
#[allow(irrefutable_let_patterns)]
fn write<O: $crate::Options>(&self, w: &mut $crate::json::Writer<'_, O>) {
const {
let _ = <Self as $crate::Variants>::MAP;
$crate::__tag_check_generic!([$($wgen)*] [$tag] {
$($($name =>)? $variant $(($($payload)*))? $(| $valias)*),*
});
};
$(
$crate::__write_internal_variant!(
self, w,
$crate::__json_key!([$case] $($name)? [$variant]),
::core::concat!("\"", $tag, "\":"),
$variant $(($($payload)*))?
);
)*
match self { $( Self::$variant { .. } => {} ),* }
}
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __json_read_internal {
($self:ident, $p:ident, $open:ident, [$($name:expr),+], $variant:ident) => {
if $( $p.match_key($name) )||+ {
$p.finish_internally_tagged()?;
*$self = Self::$variant;
::core::result::Result::Ok(true)
} else {
::core::result::Result::Ok(false)
}
};
($self:ident, $p:ident, $open:ident, [$($name:expr),+], $variant:ident ($($payload:tt)*)) => {
if $( $p.match_key($name) )||+ {
match $self {
Self::$variant(v) => {
$p.read_object_rest(v, $open)?;
}
_ => {
let mut value = ::core::default::Default::default();
$p.read_object_rest(&mut value, $open)?;
*$self = Self::$variant(value);
}
}
::core::result::Result::Ok(true)
} else {
::core::result::Result::Ok(false)
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __beve_read_internal_enum_impls {
(
[$de:lifetime $($rgen:tt)*] [$($wgen:tt)*] [$case:tt] [$tag:literal] $ty:ty {
$($($name:literal =>)? $variant:ident $(($($payload:tt)*))? $(| $valias:literal)*),* $(,)?
}
) => {
impl<$de $($rgen)*> $crate::beve::ReadInternallyTagged<$de> for $ty {
const TAG: &'static str = $tag;
#[inline]
#[allow(unused_assignments, unused_variables, unused_mut, unreachable_patterns)]
fn read_variant<O: $crate::Options>(
&mut self,
index: usize,
name: &[u8],
r: &mut $crate::beve::Reader<$de, O>,
remaining: usize,
open: usize,
) -> ::core::result::Result<bool, $crate::ErrorCode> {
let mut i = 0usize;
$(
if index == i {
return $crate::__beve_read_internal!(
self, name, r, remaining, open,
[$crate::__json_key!([$case] $($name)? [$variant]) $(, $valias)*],
$variant $(($($payload)*))?
);
}
i += 1;
)*
::core::result::Result::Ok(false)
}
}
impl<$de $($rgen)*> $crate::beve::Read<$de> for $ty {
#[inline]
fn read<O: $crate::Options>(
&mut self,
r: &mut $crate::beve::Reader<$de, O>,
) -> ::core::result::Result<(), $crate::ErrorCode> {
r.read_internally_tagged(self)
}
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __beve_write_internal_enum_impls {
(
[$($rgen:tt)*] [$($wgen:tt)*] [$case:tt] [$tag:literal] $ty:ty {
$($($name:literal =>)? $variant:ident $(($($payload:tt)*))? $(| $valias:literal)*),* $(,)?
}
) => {
impl<$($wgen)*> $crate::beve::Write for $ty {
#[inline]
#[allow(irrefutable_let_patterns)]
fn write<O: $crate::Options>(&self, w: &mut $crate::beve::Writer<'_, O>) {
const {
let _ = <Self as $crate::Variants>::MAP;
$crate::__tag_check_generic!([$($wgen)*] [$tag] {
$($($name =>)? $variant $(($($payload)*))? $(| $valias)*),*
});
};
$(
$crate::__write_internal_variant!(
self, w,
$crate::__json_key!([$case] $($name)? [$variant]),
$crate::__beve_key_bytes!($tag),
$variant $(($($payload)*))?
);
)*
match self { $( Self::$variant { .. } => {} ),* }
}
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __beve_read_internal {
($self:ident, $key:ident, $r:ident, $remaining:ident, $open:ident, [$($name:expr),+], $variant:ident) => {
if $( $key == $name.as_bytes() )||+ {
$r.finish_internally_tagged($remaining)?;
*$self = Self::$variant;
::core::result::Result::Ok(true)
} else {
::core::result::Result::Ok(false)
}
};
(
$self:ident, $key:ident, $r:ident, $remaining:ident, $open:ident,
[$($name:expr),+], $variant:ident ($($payload:tt)*)
) => {
if $( $key == $name.as_bytes() )||+ {
match $self {
Self::$variant(v) => {
$r.read_object_rest(v, $remaining, $open)?;
}
_ => {
let mut value = ::core::default::Default::default();
$r.read_object_rest(&mut value, $remaining, $open)?;
*$self = Self::$variant(value);
}
}
::core::result::Result::Ok(true)
} else {
::core::result::Result::Ok(false)
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __write_internal_variant {
($self:ident, $w:ident, $name:expr, $tag:expr, $variant:ident) => {
if let Self::$variant = $self {
$w.write_tagged($tag, $name);
return;
}
};
($self:ident, $w:ident, $name:expr, $tag:expr, $variant:ident ($($payload:tt)*)) => {
if let Self::$variant(v) = $self {
$w.write_internally_tagged($tag, $name, v);
return;
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __write_variant {
($self:ident, $w:ident, $name:expr, $key:expr, $variant:ident) => {
if let Self::$variant = $self {
$w.write_str($name);
return;
}
};
($self:ident, $w:ident, $name:expr, $key:expr, $variant:ident ($($payload:tt)*)) => {
if let Self::$variant(v) = $self {
$w.write_tagged($key, v);
return;
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __beve_enum_impls {
($($t:tt)*) => {
$crate::__beve_read_enum_impls!($($t)*);
$crate::__beve_write_enum_impls!($($t)*);
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __beve_read_enum_impls {
(
[$($rgen:tt)*] [$($wgen:tt)*] [$case:tt] [$tag:literal] $ty:ty { $($body:tt)* }
) => {
$crate::__beve_read_internal_enum_impls!(
[$($rgen)*] [$($wgen)*] [$case] [$tag] $ty { $($body)* });
};
(
[$de:lifetime $($rgen:tt)*] [$($wgen:tt)*] [$case:tt] [] $ty:ty {
$($($name:literal =>)? $variant:ident $(($($payload:tt)*))? $(| $valias:literal)*),* $(,)?
}
) => {
impl<$de $($rgen)*> $crate::beve::ReadEnum<$de> for $ty {
#[inline]
#[allow(unused_assignments, unused_variables, unused_mut)]
fn read_name(
&mut self,
index: usize,
name: &[u8],
) -> ::core::result::Result<bool, $crate::ErrorCode> {
let mut i = 0usize;
$(
if index == i {
return $crate::__beve_read_name!(
self, name,
[$crate::__json_key!([$case] $($name)? [$variant]) $(, $valias)*],
$variant $(($($payload)*))?
);
}
i += 1;
)*
::core::result::Result::Ok(false)
}
#[inline]
#[allow(unused_assignments, unused_variables, unused_mut, unreachable_patterns)]
fn read_payload<O: $crate::Options>(
&mut self,
index: usize,
name: &[u8],
r: &mut $crate::beve::Reader<$de, O>,
) -> ::core::result::Result<bool, $crate::ErrorCode> {
let mut i = 0usize;
$(
if index == i {
return $crate::__beve_read_payload!(
self, name, r,
[$crate::__json_key!([$case] $($name)? [$variant]) $(, $valias)*],
$variant $(($($payload)*))?
);
}
i += 1;
)*
::core::result::Result::Ok(false)
}
}
impl<$de $($rgen)*> $crate::beve::Read<$de> for $ty {
#[inline]
fn read<O: $crate::Options>(
&mut self,
r: &mut $crate::beve::Reader<$de, O>,
) -> ::core::result::Result<(), $crate::ErrorCode> {
r.read_enum(self)
}
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __beve_write_enum_impls {
(
[$($rgen:tt)*] [$($wgen:tt)*] [$case:tt] [$tag:literal] $ty:ty { $($body:tt)* }
) => {
$crate::__beve_write_internal_enum_impls!(
[$($rgen)*] [$($wgen)*] [$case] [$tag] $ty { $($body)* });
};
(
[$($rgen:tt)*] [$($wgen:tt)*] [$case:tt] [] $ty:ty {
$($($name:literal =>)? $variant:ident $(($($payload:tt)*))? $(| $valias:literal)*),* $(,)?
}
) => {
$crate::__beve_write_enum_body!([$($rgen)*] [$($wgen)*] [$case] $ty {
$($($name =>)? $variant $(($($payload)*))? $(| $valias)*),*
} {});
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __beve_unit_enum_impls {
(
[$($rgen:tt)*] [$($wgen:tt)*] [$case:tt] $ty:ty {
$($($name:literal =>)? $variant:ident $(| $valias:literal)*),* $(,)?
}
) => {
$crate::__beve_read_enum_impls!([$($rgen)*] [$($wgen)*] [$case] [] $ty {
$($($name =>)? $variant $(| $valias)*),*
});
$crate::__beve_write_unit_enum_impls!([$($rgen)*] [$($wgen)*] [$case] $ty {
$($($name =>)? $variant $(| $valias)*),*
});
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __beve_write_unit_enum_impls {
(
[$($rgen:tt)*] [$($wgen:tt)*] [$case:tt] $ty:ty {
$($($name:literal =>)? $variant:ident $(| $valias:literal)*),* $(,)?
}
) => {
$crate::__beve_write_enum_body!([$($rgen)*] [$($wgen)*] [$case] $ty {
$($($name =>)? $variant $(| $valias)*),*
} {
const ARRAY: ::core::option::Option<&'static [u8]> =
::core::option::Option::Some(&[$crate::beve::header::STRING_ARRAY]);
#[inline]
fn write_payload<O: $crate::Options>(
items: &[Self],
w: &mut $crate::beve::Writer<'_, O>,
) where
Self: ::core::marker::Sized,
{
for item in items {
w.write_str_body(match item {
$( Self::$variant => $crate::__json_key!([$case] $($name)? [$variant]) ),*
});
}
}
});
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __beve_write_enum_body {
(
[$($rgen:tt)*] [$($wgen:tt)*] [$case:tt] $ty:ty {
$($($name:literal =>)? $variant:ident $(($($payload:tt)*))? $(| $valias:literal)*),* $(,)?
} { $($typed:tt)* }
) => {
impl<$($wgen)*> $crate::beve::Write for $ty {
#[inline]
#[allow(irrefutable_let_patterns)]
fn write<O: $crate::Options>(&self, w: &mut $crate::beve::Writer<'_, O>) {
const {
let _ = <Self as $crate::Variants>::MAP;
};
$(
$crate::__write_variant!(
self, w,
$crate::__json_key!([$case] $($name)? [$variant]),
$crate::__beve_key_bytes!($crate::__json_key!([$case] $($name)? [$variant])),
$variant $(($($payload)*))?
);
)*
match self { $( Self::$variant { .. } => {} ),* }
}
$($typed)*
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __beve_read_name {
($self:ident, $key:ident, [$($name:expr),+], $variant:ident) => {
if $( $key == $name.as_bytes() )||+ {
*$self = Self::$variant;
::core::result::Result::Ok(true)
} else {
::core::result::Result::Ok(false)
}
};
($self:ident, $key:ident, [$($name:expr),+], $variant:ident ($($payload:tt)*)) => {
if $( $key == $name.as_bytes() )||+ {
::core::result::Result::Err($crate::ErrorCode::ExpectedObject)
} else {
::core::result::Result::Ok(false)
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __beve_read_payload {
($self:ident, $key:ident, $r:ident, [$($name:expr),+], $variant:ident) => {
if $( $key == $name.as_bytes() )||+ {
if $r.try_null()? {
*$self = Self::$variant;
::core::result::Result::Ok(true)
} else {
::core::result::Result::Err($crate::ErrorCode::ExpectedNull)
}
} else {
::core::result::Result::Ok(false)
}
};
($self:ident, $key:ident, $r:ident, [$($name:expr),+], $variant:ident ($($payload:tt)*)) => {
if $( $key == $name.as_bytes() )||+ {
match $self {
Self::$variant(v) => {
$crate::beve::Read::read(v, $r)?;
}
_ => {
let mut value = ::core::default::Default::default();
$crate::beve::Read::read(&mut value, $r)?;
*$self = Self::$variant(value);
}
}
::core::result::Result::Ok(true)
} else {
::core::result::Result::Ok(false)
}
};
}