#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

#274 in Rust patterns

Download history 1358/week @ 2024-09-08 913/week @ 2024-09-15 616/week @ 2024-09-22 532/week @ 2024-09-29 543/week @ 2024-10-06 759/week @ 2024-10-13 722/week @ 2024-10-20 633/week @ 2024-10-27 437/week @ 2024-11-03 389/week @ 2024-11-10 380/week @ 2024-11-17 433/week @ 2024-11-24 405/week @ 2024-12-01 474/week @ 2024-12-08 440/week @ 2024-12-15 304/week @ 2024-12-22

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