You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#[macro_use]externcrate qualifier_attr;// We can add a qualifier to a function// with an attribute.#[qualifiers(const)]fnconst_fn() -> u32{42}constCONST_RES:u32 = const_fn();// It's not so impressive on its own,// but with `cfg_attr`, it can be conditional.#[cfg_attr(feature = "extern_c", no_mangle, qualifiers(pub, extern "C"))]fnextern_c_fn() -> u32{42}// It even works with types, imports, and more!mod foo {#[qualifiers(pub)]structFoo{x:i32,y:i32,}}#[qualifiers(pub)]use foo::Foo;// Traits and implementations too!?#[cfg_attr(feature = "unsafe_quux", qualifiers(unsafe))]traitQuux{fnquux_the_thing();}#[cfg_attr(feature = "unsafe_quux", qualifiers(unsafe))]implQuuxforFoo{fnquux_the_thing(){println!("The thing was quuxed.");}}// You can add qualifiers to the fields of a// struct as well with this special attribute.#[field_qualifiers(x(pub), y(pub))]structPoint2{x:i32,y:i32,}#[field_qualifiers(_0(pub), _1(pub), _2(pub))]structPoint3(i32,i32,i32);
Before version 0.2.0, this crate provided a separate attribute for each kind of item. While this should generally be a small win for compile times, it is generally not justified by the additional complexity. The legacy attributes are still available behind the default legacy_attrs feature flag, but their use is currently discouraged. In order to disable the legacy attributes, add the following to your Cargo.toml:
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.
About
Procedural macro attributes for adding "qualifiers" to various items.