#derive #macro #proc-macro

macro derive2

An attribute macro that executes a function-like macro

1 unstable release

new 0.1.0 Feb 12, 2025

#440 in Procedural macros

Download history 121/week @ 2025-02-11

126 downloads per month

MIT license

7KB
67 lines

derive2

Provides #[derive2(...)], an alternative to #[derive(...)] that allows the use of macro_rules macros.

Usage

derive2 takes all its arguments, and calls them like function macros with the item it is applied to:

#[derive2(macro0, macro1)]
#[derive(Default)]
pub enum Foo {
    #[default]
    Bar,
    #[macro0(something)]
    Baz,
}

expands to

#[derive(Default)]
pub enum Foo {
    #[default]
    Bar,
    Baz,
}

macro0! {
    #[derive(Default)]
    pub enum Foo {
        #[default]
        Bar,
        #[macro0(something)]
        Baz,
    }
}
macro1! {
    #[derive(Default)]
    pub enum Foo {
        #[default]
        Bar,
        #[macro0(something)]
        Baz,
    }
}

lib.rs:

See derive2. For examples, see the github repo.

Dependencies

~215–660KB
~16K SLoC