arg_attr

Crates.ioarg_attr
lib.rsarg_attr
version0.1.0
sourcesrc
created_at2023-10-03 00:03:18.652828
updated_at2023-10-03 00:03:18.652828
descriptionSpecify the accepted arguments depending on configuration conditional checks.
homepage
repositoryhttps://github.com/JohnScience/arg_attr
max_upload_size
id990626
size4,793
Dmitrii - Demenev (JohnScience)

documentation

https://docs.rs/arg_attr

README

arg_attr

Crates.io Downloads Documentation License Dependency Status

Specify the accepted arguments depending on configuration conditional checks.

Examples

Simple yet silly example:

#![allow(dead_code)]

use arg_attr::args;

#[args(_url: String)]
fn silly_drop() {
    drop(_url);
}

In the example above, args attribute unconditionally specifies the arguments for the silly_drop function. On it's own it is fairly useless, but it can be used in combination with #[cfg_attr(...)] for conditional compilation.

use pyo3::prelude::Python;
use qualifier_attr::qualifiers;
use arg_attr::args;

// At the moment of writing, `pyo3` does not support async functions.
// https://github.com/PyO3/pyo3/issues/1632
#[cfg_attr(feature="python", args(py: Python<'_>, url: &'str))]
#[cfg_attr(not(feature="python"), args(url: &'str), qualifiers(async))]
fn fetch() {
    todo!()
}

Related crates

Commit count: 2

cargo fmt