qualifier_attr

[![Latest Version](https://img.shields.io/crates/v/qualifierattr.svg)][qualifier_attr] [![Downloads](https://img.shields.io/crates/d/qualifierattr.svg)][qualifier_attr] [![Documentation](https://docs.rs/qualifierattr/badge.svg)][qualifier_attr/docs] [![License](https://img.shields.io/crates/l/qualifierattr.svg)][qualifier_attr/license] [![Dependency Status](https://deps.rs/repo/github/JohnScience/qualifierattr/status.svg)][qualifier_attr/depstatus]

Procedural macro attributes for adding "qualifiers" to various items.

At the moment, the crate supports the following "qualifiers":

Limitations

Examples

```rust

[macro_use]

extern crate qualifier_attr;

// We can add a qualifier to a function // with an attribute.

[qualifiers(const)]

fn const_fn() -> u32 { 42 }

const CONSTRES: u32 = constfn();

// It's not so impressive on its own, // but with cfg_attr, it can be conditional.

[cfgattr(feature = "externc", no_mangle, qualifiers(pub, extern "C"))]

fn externcfn() -> u32 { 42 }

// It even works with types, imports, and more! mod foo { #[qualifiers(pub)] struct Foo { x: i32, y: i32, } }

[qualifiers(pub)]

use foo::Foo;

// Traits and implementations too!?

[cfgattr(feature = "unsafequux", qualifiers(unsafe))]

trait Quux { fn quuxthething(); }

[cfgattr(feature = "unsafequux", qualifiers(unsafe))]

impl Quux for Foo { fn quuxthething() { 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))]

struct Point2 { x: i32, y: i32, }

[fieldqualifiers(0(pub), _1(pub), _2(pub))]

struct Point3(i32, i32, i32); ```

Learn more about cfg_attr here.

Similar crates

License

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.