#[doc(hidden)]
#[macro_export]
macro_rules! enum_derive_util {
(@as_expr $e:expr) => {$e};
(@as_item $($i:item)+) => {$($i)+};
(@first_expr $head:expr, $($tail:expr),*) => {$head};
(@first_expr $head:expr) => {$head};
(
@collect_unitary_variants ($callback:ident { $($args:tt)* }),
($(,)*) -> ($($var_names:ident,)*)
) => {
enum_derive_util! {
@as_item
$callback!{ $($args)* ($($var_names),*) }
}
};
(
@collect_unitary_variants $fixed:tt,
(#[$_attr:meta] $($tail:tt)*) -> ($($var_names:tt)*)
) => {
enum_derive_util! {
@collect_unitary_variants $fixed,
($($tail)*) -> ($($var_names)*)
}
};
(
@collect_unitary_variants $fixed:tt,
($var:ident $(= $_val:expr)*, $($tail:tt)*) -> ($($var_names:tt)*)
) => {
enum_derive_util! {
@collect_unitary_variants $fixed,
($($tail)*) -> ($($var_names)* $var,)
}
};
(
@collect_unitary_variants ($name:ident),
($var:ident $_struct:tt, $($tail:tt)*) -> ($($var_names:tt)*)
) => {
const _error: () = "cannot parse unitary variants from enum with non-unitary variants";
};
(
@collect_unary_variants ($callback:ident { $($args:tt)* }),
($(,)*) -> ($($out:tt)*)
) => {
enum_derive_util! {
@as_item
$callback!{ $($args)* ($($out)*) }
}
};
(
@collect_unary_variants $fixed:tt,
(#[$_attr:meta] $($tail:tt)*) -> ($($out:tt)*)
) => {
enum_derive_util! {
@collect_unary_variants $fixed,
($($tail)*) -> ($($out)*)
}
};
(
@collect_unary_variants $fixed:tt,
($var_name:ident($var_ty:ty), $($tail:tt)*) -> ($($out:tt)*)
) => {
enum_derive_util! {
@collect_unary_variants $fixed,
($($tail)*) -> ($($out)* $var_name($var_ty),)
}
};
(
@collect_unary_variants $fixed:tt,
($var_name:ident(pub $var_ty:ty), $($tail:tt)*) -> ($($out:tt)*)
) => {
enum_derive_util! {
@collect_unary_variants $fixed,
($($tail)*) -> ($($out)* $var_name($var_ty),)
}
};
(
@collect_unary_variants ($name:ident),
($var:ident $_struct:tt, $($tail:tt)*) -> ($($_out:tt)*)
) => {
const _error: () = "cannot parse unary variants from enum with non-unary tuple variants";
};
}