1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
extern crate proc_macro;
use TokenStream;
use ;
use ;
/// This attribute macro converts a Rust function into a function that returns its own definition as a string.
///
/// The generated function has the same signature as the original function, but instead of executing the original code,
/// it returns a string containing the entire source code of the function, including doc strings and other attributes.
///
/// This can be useful for sending the function's code to a large language model for further processing.
///
/// # Usage
///
/// Simply annotate your function with `#[ai_function]`.
///
/// ```ignore
/// #[ai_function]
/// 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`.
///
/// # Limitations
///
/// The `#[ai_function]` macro currently does not support functions with complex control flow like loops or conditionals.
/// It only supports simple function definitions.
///
/// # Example
///
/// ```ignore
/// #[ai_function]
/// fn add(a: i32, b: i32) -> i32 {
/// a + b
/// }
///
/// assert_eq!(add(2, 3), "fn add(a: i32, b: i32) -> i32 {\n a + b\n}");
/// ```