mass-cfg-attr

Crates.iomass-cfg-attr
lib.rsmass-cfg-attr
version0.2.0
sourcesrc
created_at2023-01-23 00:22:07.971176
updated_at2023-01-23 22:54:48.302351
descriptionA way to mass toggle cfg-attr on attributes
homepage
repositoryhttps://github.com/Standard-Games/mass-cfg-attr
max_upload_size
id765443
size17,737
Daniel Mason (Gisleburt)

documentation

README

Mass Cfg Attr

This custom derive macro allows you to wrap multiple attributes in the same #[cfg_attr(..., ...)]

For example, you might be using another custom derive to tag methods for additional wiring, but in the test runtime, that additional wiring won't work. To work around this you'd have to use cfg_attr over and over again. This introduces extra work, makes your code harder to read and creates extra risk. mass_cfg_attr helps mitigate that:

Without mass_cfg_attr:

#[derive(SomeAutoWirer)]
struct MyStruct;

#[cfg_attr(not(any(test, doctest)), auto_wire)]
impl MyStruct {
    #[cfg_attr(not(any(test, doctest)), wire(options))]
    fn func_one(self) {
        // ...
    }

    #[cfg_attr(not(any(test, test)), wire(options))] // mistake the compiler won't see
    fn func_two(self) {
        // ...
    }

    #[cfg_attr(not(any(test, doctest)), wire(options))]
    fn func_three(self) {
        // ...
    }
}

With mass_cfg_attr

#[derive(SomeAutoWirer)]
struct MyStruct;

#[mass_cfg_attr(not(any(test, doctest)), [auto_wire, wire, wire_more])]
#[auto_wire]
impl MyStruct {
    #[wire(options)]
    fn func_one(self) {
        // ...
    }

    #[wire(options)]
    fn func_two(self) {
        // ...
    }

    #[wire_more(options)]
    fn func_three(self) {
        // ...
    }
}
Commit count: 7

cargo fmt