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

no-std generics

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

22 releases

Uses new Rust 2021

0.4.4 May 24, 2022
0.4.3 May 19, 2022
0.3.2 Jul 31, 2021
0.2.8 Jul 18, 2021
0.0.1 Sep 18, 2020

#147 in Rust patterns

Download history 14/week @ 2022-04-14 14/week @ 2022-04-21 360/week @ 2022-04-28 597/week @ 2022-05-05 1047/week @ 2022-05-12 1692/week @ 2022-05-19 1043/week @ 2022-05-26 973/week @ 2022-06-02 432/week @ 2022-06-09 460/week @ 2022-06-16 589/week @ 2022-06-23 464/week @ 2022-06-30 474/week @ 2022-07-07 455/week @ 2022-07-14 488/week @ 2022-07-21 439/week @ 2022-07-28

1,917 downloads per month
Used in 7 crates (4 directly)

MIT/Apache

48KB
1.5K SLoC

maintenance: actively developed

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