| Crates.io | struargs_derive |
| lib.rs | struargs_derive |
| version | 0.1.1 |
| created_at | 2025-10-20 10:45:22.122037+00 |
| updated_at | 2025-10-20 11:28:50.62228+00 |
| description | A macro that converts a structure into a Command parameter list |
| homepage | |
| repository | https://github.com/yk0n9/struargs |
| max_upload_size | |
| id | 1891735 |
| size | 6,648 |
A macro that builds a structure into a Command parameter list
use struargs::Args;
#[derive(Debug, Args)]
struct StructArg {
size: Option<i32>,
name: Option<String>,
#[args(rename = "type")]
ty: Option<String>,
num: f32,
}
let s = StructArg {
size: None,
name: Some("123".to_string()),
ty: Some("Arg".to_string()),
num: 100.1,
};
assert_eq!(
s.args(),
vec![
"--name".to_string(),
123.to_string(),
"--type".to_string(),
"Arg".to_string(),
"--num".to_string(),
"100.1".to_string(),
]
);
it expand to (all field must impl Display)
impl ::struargs::Args for StructArg {
fn args(&self) -> Vec<String> {
let mut args = ::alloc::vec::Vec::new();
if let Some(ref arg) = self.size {
args.extend(["--size".to_string(), arg.to_string()]);
}
if let Some(ref arg) = self.name {
args.extend(["--name".to_string(), arg.to_string()]);
}
if let Some(ref arg) = self.ty {
args.extend(["--type".to_string(), arg.to_string()]);
}
args.extend(["--num".to_string(), self.num.to_string()]);
args
}
}