Crates.io | opt_args |
lib.rs | opt_args |
version | 2.0.0 |
source | src |
created_at | 2022-03-18 17:55:38.491747 |
updated_at | 2024-03-15 16:40:18.336723 |
description | Create macros for functions and structs with default values |
homepage | |
repository | https://github.com/Princic-1837592/opt_args |
max_upload_size | |
id | 552815 |
size | 31,171 |
This crate allows you to auto-generate macros to call functions and instantiate structs with default named arguments
Import the macro and use it on a function or struct like this
use opt_args::opt_args;
opt_args! {
fn function(a: i32, b: &str = "default", c: (u8,)?) -> (i32, &str, (u8,)) {
(a, b, c)
}
}
opt_args! {
#[derive(Debug, PartialEq, Eq)]
struct Struct {
x: i32,
y: i32 = 1,
z: i32?,
other: Option<Box<Self>>?,
}
}
To auto-generate macros that can be used like this
fn main() {
assert_eq!(
function!(1, b = "not the default"),
(1, "not the default", (0,))
);
assert_eq!(
Struct!(4, z = 5),
Struct {
x: 4,
y: 1,
z: 5,
other: None
}
);
}
Full documentation here