| Crates.io | patternutils-derive |
| lib.rs | patternutils-derive |
| version | 0.1.1 |
| created_at | 2025-06-14 20:02:32.236405+00 |
| updated_at | 2025-06-15 17:47:28.469357+00 |
| description | Derive macros & attribute macros for patternutils |
| homepage | |
| repository | https://github.com/TannYuld/patternutils/tree/master |
| max_upload_size | |
| id | 1712631 |
| size | 21,901 |
This crate provides procedural macros for Patternutils crate.
Builder derive macro
Implements the Builder pattern by generating an associated Builder struct with fluent setter methods and flexible configuration options.
observer macro (for traits)
Implements the Observer pattern by generating a Publisher struct for the specified trait, allowing multiple observers to subscribe to instances of types implementing that trait.
use patternutils::Builder;
#[derive(Builder)]
#[builder_attr(name = "CommandCreator", opt_in)]
struct Command {
#[builder_field(name = "value", include = true)]
definition: String,
#[builder_field(include = true)]
arg_count: usize,
accepted_flag_fallback: fn(val: usize) -> usize,
childs: Vec<Command>,
}
let mut builder = Command::builder();
let command = builder
.value(String::from("my-command"))
.arg_count(3)
.build(|val| val + 5, vec![]);
assert_eq!(command.definition, String::from("my-command"));
assert_eq!(command.arg_count, 3);
assert_eq!((command.accepted_flag_fallback)(67), 72);
assert_eq!(command.childs.len(), 0);