apply-macro 1.0.1

An attribute macro to apply function-like macros.
Documentation
apply-macro-1.0.1 has been yanked.
An attribute macro to apply function-like macros. It can improve the readability of your code. This crate has *no* dependency so you don't need to worry about compile time. # Examples ``` use apply_macro::apply; macro_rules! common_derive { ($input:item) => { #[derive(Debug, PartialEq)] $input }; } #[apply(common_derive)] struct Num(i32); assert_eq!(Num(-1), Num(-1)); assert_ne!(Num(1), Num(-1)); #[apply(common_derive,)] struct TrailingCommaIsAllowed; assert_eq!(TrailingCommaIsAllowed, TrailingCommaIsAllowed); ``` The `#[apply(common_derive)]` on `Num` expands to: ``` # macro_rules! common_derive { # ($dummy:item) => {}; # } common_derive! { struct Num(i32); } ``` Multiple arguments are allowed and seperated by commas: ``` use apply_macro::apply; macro_rules! derive_debug { { #[$attr:meta] // will receive `#[apply(derive_partial_eq)]` $input:item } => { #[$attr] // avoid "error: macro attributes must be placed before `#[derive]`" #[derive(Debug)] $input }; } macro_rules! derive_partial_eq { ($input:item) => { #[derive(PartialEq)] $input }; } #[apply(derive_debug, derive_partial_eq)] struct Num(i32); assert_eq!(Num(-1), Num(-1)); assert_ne!(Num(1), Num(-1)); #[apply(derive_debug, derive_partial_eq,)] struct TrailingCommaIsAllowed; assert_eq!(TrailingCommaIsAllowed, TrailingCommaIsAllowed); ``` Empty argument is also allowed (consistent with `#[derive()]`): ``` use apply_macro::apply; #[apply()] #[derive()] // consistent # #[allow(unused_attributes, dead_code)] struct EmptyArg; ``` Although, as a procedural macro, `#[apply]` can't be banned: ``` use apply_macro::apply; #[apply] # #[allow(dead_code)] struct Oops; ```