In a vaccum, remove_macro_call
[attribute] is fairly useless because unconditional application of #[remove_macro_call]
[attribute] to either declarative or procedural function-like macros yields the same result as writing only the code inside of the enclosing punctuation (parentheses, braces, or square brackets).
```rust use removemacrocall::removemacrocall;
macrorules! reorderstatements { ($s1:stmt; $s2:stmt;) => { $s2; $s1; }; }
let mut n = 2; reorder_statements! { n += 2; n *= 2; }
// 2*2+2 = 6 assert_eq!(n, 6);
// The new variable shadows the old one let mut n = 2;
n += 2; n *= 2;
// (2+2)*2 = 8 assert_eq!(n, 8);
// The new variable shadows the old one let mut n = 2;
reorder_statements! { n += 2; n *= 2; }
// (2+2)*2 = 8 assert_eq!(n, 8); ```
However, with cfg_attr
remove_macro_call
allows one to remove macro calls conditionally. One important application of such combination is providing support for stable toolchain while also providing functionality relying on Nightly features.
```rust, ignore
feature = "const_trait_impl",
feature = "const_default_impls",
feature = "const_fn_trait_bound"
)))] use consttraitimpl::unconsttraitimpl; use core::{default::Default, marker::PhantomData};
feature = "const_trait_impl",
feature = "const_default_impls",
feature = "const_fn_trait_bound"
))] use removemacrocall::removemacrocall;
// Since ZST is both Eq and and PartialEq, it has structural match // https://github.com/rust-lang/rust/issues/63438
pub struct ZST
pub trait TraitName {}
all(
feature = "const_trait_impl",
feature = "const_default_impls",
feature = "const_fn_trait_bound"
),
remove_macro_call
)]
unconsttraitimpl! {
impl
// With cargo build --features const_trait_impl, const_default_impls, const_fn_trait_bound
// or with `cargo build --all-features, the code below is expanded as is. Otherwise,
// it gets "unconsted" to be supported by stable toolchain.
all(
feature = "const_trait_impl",
feature = "const_default_impls",
feature = "const_fn_trait_bound"
),
remove_macro_call
)]
unconsttraitimpl! {
impl
Note: In the real code, the example above could be replaced with a simpler version relying on cfg_aliases
crate.
You can learn more about const_trait_impl
here:
* GitHub
* crates.io
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.