Crates.io | ai_actions |
lib.rs | ai_actions |
version | |
source | src |
created_at | 2025-05-04 15:41:47.838986+00 |
updated_at | 2025-05-04 15:46:49.6906+00 |
description | Macros for ai actions |
homepage | |
repository | |
max_upload_size | |
id | 1659725 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
The ai_action
crate provides a Rust procedural macro that allows you to transform any function into a function that returns its own definition as a string. This is useful for sending the function's code to a large language model for further processing.
Add the following to your Cargo.toml
file:
[dependencies]
ai_action = "0.1.0"
Then run cargo build to download and compile the ai_action crate.
To use the ai_action macro, simply annotate your function with #[ai_action].
use ai_action::ai_action;
#[ai_action]
fn example_function(arg: i32) -> i32 {
arg \* 2
}
When you call example_function(), instead of returning arg * 2, it will return a string containing the source code of the example_function.
The #[ai_action] macro currently does not support functions with complex control flow like loops or conditionals. It only supports simple function definitions.
use ai_actions::ai_action;
#[ai_action]
fn add(a: i32, b: i32) -> i32 {
a + b
}
fn main() {
assert_eq!(add(2, 3), "fn add(a: i32, b: i32) -> i32 {\n a + b\n}");
}