#macro-rules #macro #parser #where

no-std generics

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

26 releases

0.5.3 Feb 28, 2024
0.5.1 Oct 30, 2023
0.4.4 May 24, 2022
0.3.2 Jul 31, 2021
0.2.6 Nov 3, 2020

#467 in Rust patterns

Download history 701/week @ 2024-02-15 982/week @ 2024-02-22 561/week @ 2024-02-29 830/week @ 2024-03-07 540/week @ 2024-03-14 621/week @ 2024-03-21 634/week @ 2024-03-28 474/week @ 2024-04-04 420/week @ 2024-04-11 397/week @ 2024-04-18 404/week @ 2024-04-25 320/week @ 2024-05-02 319/week @ 2024-05-09 379/week @ 2024-05-16 331/week @ 2024-05-23 392/week @ 2024-05-30

1,467 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