Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- macro_rules! derive_match {
- (@with_dollar![$dol:tt]
- $matching_Enum:ident in [$($absolute_path:tt)*],
- $( #[$($meta:meta)*] )*
- $pub:vis
- enum $Enum:ident {
- $(
- $( #[$($variant_meta:meta)*] )*
- $VariantN:ident $value:tt,
- )*
- }
- ) => (
- $( #[$($meta)*] )*
- $pub
- enum $Enum {
- $(
- $( #[$($variant_meta)*] )*
- $VariantN $value,
- )*
- }
- macro_rules! $matching_Enum {(
- let $dol Variant:tt $dol pat:tt = $dol expr:expr;
- $dol($dol body:tt)*
- ) => ({
- #[allow(unused_imports)]
- use $($absolute_path)*::$Enum::*;
- match $dol expr {
- $(
- $VariantN $dol pat => {
- $dol($dol body)*
- },
- )*
- }
- })}
- );
- (
- $matching_Enum:ident in [$($absolute_path:tt)*],
- $( #[$($meta:meta)*] )*
- $pub:vis
- enum $Enum:ident {
- $(
- $( #[$($variant_meta:meta)*] )*
- $VariantN:ident $value:tt
- ),* $(,)?
- }
- ) => (derive_match!{@with_dollar![$]
- $matching_Enum in [$($absolute_path)*],
- $( #[$($meta)*] )*
- $pub
- enum $Enum {
- $(
- $( #[$($variant_meta)*] )*
- $VariantN $value,
- )*
- }
- });
- }
- derive_match!{
- matching_Foo in [crate],
- enum Foo {
- Foo1(Bar<u8>),
- Foo2(Bar<u32>),
- }
- }
- struct Bar<U> (U);
- impl<U> Bar<U> {
- fn bar (self: &'_ Self, word: &'_ str)
- {}
- }
- fn foo (something: Foo) {
- let a_word = "A word";
- matching_Foo!{
- let FooN(inner) = something;
- inner.bar(a_word);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement