| Crates.io | ai-descriptor |
| lib.rs | ai-descriptor |
| version | 0.11.0 |
| created_at | 2024-11-17 05:01:59.266977+00 |
| updated_at | 2025-07-08 01:18:16.259155+00 |
| description | Provides a proc macro we can use to annotate enums for facilitating itemization and description using an AI model |
| homepage | https://github.com/klebs6/klebs-general |
| repository | https://github.com/klebs6/klebs-general |
| max_upload_size | |
| id | 1450901 |
| size | 34,204 |
ai-descriptor is a Rust procedural macro crate that automatically implements the AIDescriptor trait for enums based on the #[ai("...")] attributes provided on each variant. This helps eliminate boilerplate code and makes your codebase cleaner and more maintainable.
AIDescriptor for your enums, and the macro will generate the implementation based on the #[ai("...")] attributes.#[ai("...")] attribute, the macro will produce a compile-time error.RandomConstructible.Add the following to your Cargo.toml:
[dependencies]
ai-descriptor = "0.1.0"
In your Rust file, import the AIDescriptor macro:
use ai_descriptor::AIDescriptor;
AIDescriptor for EnumsYou can automatically implement AIDescriptor for your enums by using the #[derive(AIDescriptor)] macro and adding #[ai("...")] attributes to each variant.
use ai_descriptor::AIDescriptor;
use std::borrow::Cow;
#[derive(AIDescriptor)]
enum Emotion {
#[ai("A feeling of great pleasure or happiness.")]
Joy,
#[ai("A strong feeling of displeasure or hostility.")]
Anger,
#[ai("A feeling of sadness or grief.")]
Sadness,
}
impl Emotion {
fn ai(&self) -> Cow<'_, str> {
// Generated automatically by the macro
}
}
ai() MethodAfter deriving AIDescriptor, you can use the ai() method:
fn main() {
let emotion = Emotion::Joy;
println!("Description: {}", emotion.ai());
}
Description: A feeling of great pleasure or happiness.
#[ai("...")]#[derive(AIDescriptor)].AIDescriptor derive macro only works with enums.#[ai] Attributes: All variants must have the #[ai("...")] attribute; otherwise, a compile-time error will occur.ai-descriptor crate can be used alongside the random-constructible crate to provide both random instantiation and AI descriptions for your enums.This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
proc-macro crate for procedural macros and syn and quote for parsing and generating Rust code.For questions or suggestions, feel free to open an issue or contact the maintainer.
Happy coding!