Crate qualifiers

Source
Expand description

qualifiers is a lightweight attribute to apply qualifiers to items.

use qualifiers::qualifiers;

// I'm public and `const` now!
#[qualifiers(pub const)]
fn multiply(x: i32, y: i32) -> i32 {
    x * y
}

// Every type of item is supported.
#[qualifiers(unsafe)]
pub trait Greeter {
    #[qualifiers(async)]
    fn greet(&self);
}

Qualifiers are any type of keyword that precedes an item definition. This crate currently supports the ones below:

  • pub, pub(crate), pub(in super), etc.
  • const
  • async
  • unsafe, safe
  • extern "C", etc.

This may not seem very useful on its own, but it becomes powerful when used in combination with cfg_attr.

#[cfg_attr(feature = "const", qualifiers(const))]
fn maybe_const() { /* ... */ }

§Similar crates

const_fn provides an attribute to apply const to functions. It has a built-in feature to do this conditionally based on the detected compiler version. Like this crate, it has no dependencies.

qualifier_attr provides an attribute very similar to the one in this crate, but it may not be as lightweight due to its dependency on proc-macro2, quote, and syn. However, it supports the default keyword and applying qualifiers to struct fields, features this crate currently lacks.

§Minimum supported Rust version

The MSRV is currently 1.56.

This may change between minor releases.

§License

This crate is licensed under the Blue Oak Model License 1.0.0.

Attribute Macros§

qualifiers
Applies qualifiers to an item.