macro_rules! parse_split_generics {
    (
        $(:: $(@$leading:tt@)? )? $first:ident $(:: $trailing:ident)* ! {$($prefix:tt)*}

        ($($generics:tt)*)
    ) => { ... };
}
Available on crate feature generics_parsing only.
Expand description

Transforms generic parameters to a form easily parsable by a callback macro.

Examples

Basic

Basic example of the syntax this macro expects and passes to a callback macro.

use core_extensions::parse_split_generics;
 
 
// This calls the `foo` macro
parse_split_generics!{
    // The first tokens passed to the `crate::foo` macro
    foo!{ hello "world" }
    // The parsed tokens
    ('a: 'b, 'b, T: 'a + Foo = Bar, const X: u32 = 10, U = Baz, V)
}
 
#[macro_export]
macro_rules! foo {
    (
        $fn_name:ident $value:literal
        // The generic paremeters in the order they came in
        // Bounds always have a trailing `+``
        (
            ('a:('b +))
            ('b:()) 
            (type T:('a + Foo +) = $def_t:ty,)
            (const X: $ty_x:ty = $def_x:expr,)
            (type U:() = $def_u:ty,)
            (type V:(),)
        )
        // The generic parameters are classified by kind
        // Bounds always have a trailing `+``
        // Generic parameters always have a trailing `,`
        (
            ('a:('b +), 'b:(),)                                      // lifetimes
            (T:('a + Foo +) = $defb_t:ty, U:() = $defb_u:ty, V:(),)  // types
            (X: $tyb_x:ty = $defb_x:expr,)                           // constants
        )
    ) => {

    };
}