Crates.io | arg_attr |
lib.rs | arg_attr |
version | 0.1.0 |
source | src |
created_at | 2023-10-03 00:03:18.652828 |
updated_at | 2023-10-03 00:03:18.652828 |
description | Specify the accepted arguments depending on configuration conditional checks. |
homepage | |
repository | https://github.com/JohnScience/arg_attr |
max_upload_size | |
id | 990626 |
size | 4,793 |
Specify the accepted arguments depending on configuration conditional checks.
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!()
}