#macro #parser #generics #where #macro-rules

no-std generics

Provides macros for parsing generics (with optional where clause) in macro_rules!

17 releases

0.3.2 Jul 31, 2021
0.3.1 Jul 20, 2021
0.2.8 Jul 18, 2021
0.2.6 Nov 3, 2020
0.0.1 Sep 18, 2020

#278 in Rust patterns

Download history 309/week @ 2021-06-27 100/week @ 2021-07-04 90/week @ 2021-07-11 404/week @ 2021-07-18 125/week @ 2021-07-25 477/week @ 2021-08-01 95/week @ 2021-08-08 58/week @ 2021-08-15 155/week @ 2021-08-22 75/week @ 2021-08-29 38/week @ 2021-09-05 71/week @ 2021-09-12 65/week @ 2021-09-19 43/week @ 2021-09-26 6/week @ 2021-10-03 30/week @ 2021-10-10

371 downloads per month
Used in 7 crates (4 directly)

MIT/Apache

47KB
1.5K SLoC

generics-parse

Provides macros for parsing generics and where clauses in macro_rules!.

pub trait TheTrait { }

#[doc(hidden)]
pub use generics::parse as generics_parse;
#[doc(hidden)]
pub use std::compile_error as std_compile_error;

#[macro_export]
macro_rules! impl_the_trait {
    (
        $name:ident $($token:tt)*
    ) => {
        $crate::generics_parse! {
            $crate::impl_the_trait {
                @impl $name
            }
            $($token)*
        }
    };
    (
        @impl $name:ident [$($g:tt)*] [$($r:tt)*] [$($w:tt)*]
    ) => {
        impl $($g)* $crate::TheTrait for $name $($r)* $($w)* { }
    };
    (
        @impl $name:ident [$($g:tt)*] [$($r:tt)*] [$($w:tt)*] $($token:tt)+ 
    ) => {
        $crate::std_compile_error!(
            "invalid input, allowed input is '$name $( < $generics > $(where $where_clause)? )?'"
        );
    };
}

No runtime deps