An active attribute belongs to an attribute macro and removes itself during attribute processing after the macro expands. Derive macro attributes are inert instead. section 8.7
Removal matters when an attribute macro emits no replacement item: keeping the annotation would leave an attribute attached to something that has disappeared. section 8.7
A flexible attribute macro
The invocation #[public(exclude(fourth, third))] carries custom properties to an attribute macro. The macro can make selected struct fields public while leaving excluded fields unchanged; the active annotation is then consumed during processing. section 8.7
Listing 8.34 example.rs, with a struct
use make_public_macro::public;
#[public(exclude(fourth, third))] #1
struct Example {
first: String,
pub second: u32,
third: bool,
fourth: String,
}
impl Example {
pub fn new() -> Self { #2
Example {
first: "first".to_string(),
// etc.
}
}
}
Inspect the attribute-macro invocation and its excluded-field configuration. section 8.7
