#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

#213 in Rust patterns

Download history 417/week @ 2024-08-12 360/week @ 2024-08-19 472/week @ 2024-08-26 927/week @ 2024-09-02 952/week @ 2024-09-09 888/week @ 2024-09-16 651/week @ 2024-09-23 491/week @ 2024-09-30 543/week @ 2024-10-07 936/week @ 2024-10-14 583/week @ 2024-10-21 585/week @ 2024-10-28 437/week @ 2024-11-04 378/week @ 2024-11-11 401/week @ 2024-11-18 419/week @ 2024-11-25

1,690 downloads per month
Used in 8 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