ai-descriptor-trait
ai-descriptor-trait is a Rust crate that provides a simple, structured way to describe items with features in a human-readable format using AI-style descriptors. It defines reusable traits to represent items and their features, then generates a formatted description for these items.
Features
-
Modular Traits:
ItemFeature: Represents an individual feature with a text description.ItemWithFeatures: Represents an item containing a header and a collection of features.AIDescriptor: Automatically formats an item's header and its features into a human-readable string.
-
Convenience: Automatically composes structured descriptions for any type implementing
ItemWithFeatures. -
Flexibility: Uses
Cow<'_, str>for efficient memory management, allowing seamless use of owned and borrowed strings.
Example Usage
Below is an example of how to implement and use the provided traits:
use Cow;
use ;
Output:
My Cool Item
It has the following features:
- Lightweight
- Durable
- Eco-friendly
Integration with Your Project
Add the following to your Cargo.toml:
[]
= "0.1.0"
Running Tests
Unit tests are provided to ensure the functionality of the AIDescriptor implementation. Run the tests using:
Key Concepts
Traits Overview
-
ItemFeature: Defines a single feature for an item. -
ItemWithFeatures: Represents an item with a header and a collection of features. -
AIDescriptor: Generates a formatted description of any item implementingItemWithFeatures.
Test Example
A test is provided in the module to ensure the AIDescriptor works as expected:
License
This crate is licensed under the MIT License.
Contributions are welcome! Feel free to fork the repository and submit pull requests.