3 releases
Uses new Rust 2024
| 0.1.3 | Jul 13, 2025 |
|---|---|
| 0.1.2 | Jun 20, 2025 |
| 0.1.1 | Mar 31, 2025 |
#35 in #axis
777 downloads per month
Used in 106 crates
(via batch-mode)
215KB
3K
SLoC
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 batch_mode_token_expansion_axis_derive::TokenExpansionAxis;
use std::borrow::Cow;
#[derive(TokenExpansionAxis, Debug)]
#[system_message_goal("Transform tokens along multiple axes")]
enum ExampleExpanderAxis {
#[axis("lang => Expands the language dimension")]
Language,
#[axis("style => Expands the style dimension")]
Style,
}
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:[dependencies] batch-mode-token-expansion-axis = "0.1" batch-mode-token-expansion-axis-derive = "0.1" -
Import and Use:
use batch_mode_token_expansion_axis_derive::TokenExpansionAxis; use batch_mode_token_expansion_axis::{TokenExpansionAxis, AxisName, AxisDescription}; #[derive(TokenExpansionAxis)] enum MyAxis { #[axis("color => Expand color variations")] Color, #[axis("size => Expand size variations")] Size, } -
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.
Dependencies
~28–52MB
~719K SLoC