batch-mode-token-expansion-axis-derive
This crate provides a procedural macro #[derive(TokenExpansionAxis)] for enumerations, enabling automatic implementation of axis-related traits from the batch-mode-token-expansion-axis crate. By specifying attributes like #[system_message_goal("...")] and #[axis("axis_name => axis_description")], you can generate:
- AxisName and AxisDescription implementations for each variant.
- A data-carrying struct that stores expanded data (e.g.,
Expanded...). - An aggregator struct that implements
TokenExpanderandSystemMessageGoal, tying the process together.
Features
- system_message_goal attribute: Annotate the enum with a default or custom system message goal (e.g.,
#[system_message_goal("Convert tokens to JSON")]). - axis attribute: For each variant, specify an axis name and description (e.g.,
#[axis("my_axis => Provides an axis for expansion")]). - Generated Aggregator: Automatically implements
Default,Named,TokenExpander, andSystemMessageGoal, facilitating batch expansions. - Data-carrying Struct: A structured result type (e.g.,
Expanded...) that includes fields derived from your enumeration variants.
Example Usage
use TokenExpansionAxis;
use Cow;
When this derives, it generates:
- Implementations for
AxisName,AxisDescription, andTokenExpansionAxisonExampleExpanderAxis. - A data-carrying struct named
ExpandedExampleExpander(if you strip off theExpanderAxissuffix, it becomesExpandedExample—the macro handles naming automatically). - An aggregator struct named
ExampleExpander, which implements traits likeTokenExpanderandSystemMessageGoal.
Getting Started
-
Add to
Cargo.toml:[] = "0.1" = "0.1" -
Import and Use:
use TokenExpansionAxis; use ; -
Leverage the Generated Code:
- Instantiating the aggregator (e.g.,
MyExpander) allows accessing all enum variants asArc<dyn TokenExpansionAxis>. - The expanded struct (e.g.,
ExpandedMy) supports serialization, deserialization, and other derived functionality.
- Instantiating the aggregator (e.g.,
This library is designed to integrate seamlessly with batch-mode-token-expansion-axis, providing a clean, DRY approach to multi-dimensional token expansions.