synapto_derive/lib.rs
1use proc_macro::TokenStream;
2use quote::quote;
3use syn::{DeriveInput, parse_macro_input};
4
5#[proc_macro_derive(LLMSafe)]
6pub fn llm_safe_derive(input: TokenStream) -> TokenStream {
7 // Parse the input tokens into a syntax tree
8 let ast = parse_macro_input!(input as DeriveInput);
9
10 // Get the name of the struct or enum we are deriving on
11 let name = &ast.ident;
12
13 // Extract the generics (lifetimes, type parameters, where clauses)
14 let (impl_generics, ty_generics, where_clause) = ast.generics.split_for_impl();
15
16 // Generate the Rust code for the implementation
17 let expanded = quote! {
18 // This generates: impl<T> LLMSafe for MyStruct<T> where T: ... {}
19 impl #impl_generics LLMSafe for #name #ty_generics #where_clause {}
20 };
21
22 // Return the generated code as a TokenStream for the compiler to use
23 TokenStream::from(expanded)
24}