named-item-derive
A single procedural macro crate that integrates with named-item to provide robust name-management for Rust structs.
Features
#[derive(NamedItem)]: The single macro that implements:Named,SetName,DefaultName,ResetName- Conditionally implements
NameHistoryif#[named_item(history="true")]is specified. - Conditionally implements
NamedAlias(includingclear_aliases) if#[named_item(aliases="true")]is specified.
- Supports custom default names via
#[named_item(default_name="...")]. - Supports default aliases via
#[named_item(default_aliases="foo,bar")]. - Enforces a
name: Stringfield. Ifhistory="true", it also requiresname_history: Vec<String>; ifaliases="true", requiresaliases: Vec<String>.
Usage
First, add this crate and its companion named-item as dependencies in your Cargo.toml:
[]
= "x.y.z"
= { = "../named-item-derive" } # or your version
Then, in your code:
use NamedItem;
use ;
When history="true", each call to set_name automatically appends the new name to name_history, while aliases="true" implements the NamedAlias trait with add_alias, aliases, and clear_aliases.
Tests
We include:
- Integration tests under
tests/integration.rs. - Optionally, UI tests (compile-fail) with trybuild in
tests/ui/.
Run:
to ensure all tests pass.
License
This project is licensed under the MIT license. See LICENSE for details.
Contributing
Pull requests are welcome! Please open an issue for major changes to discuss them first.