1 unstable release
0.1.0 | Oct 3, 2023 |
---|
#2713 in Rust patterns
5KB
arg_attr
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
Dependencies
~260–710KB
~17K SLoC