Crates.io | mass-cfg-attr |
lib.rs | mass-cfg-attr |
version | 0.2.0 |
source | src |
created_at | 2023-01-23 00:22:07.971176 |
updated_at | 2023-01-23 22:54:48.302351 |
description | A way to mass toggle cfg-attr on attributes |
homepage | |
repository | https://github.com/Standard-Games/mass-cfg-attr |
max_upload_size | |
id | 765443 |
size | 17,737 |
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) {
// ...
}
}