ccanvas_config_derive/
lib.rs

1use proc_macro::TokenStream;
2use quote::quote;
3use syn::{parse_macro_input, DeriveInput};
4
5#[proc_macro_derive(CcanvasConfig)]
6pub fn derive_ccanvas_config(input: TokenStream) -> TokenStream {
7    // Parse the input tokens into a syntax tree
8    let input = parse_macro_input!(input as DeriveInput);
9
10    // Get the name of the struct being derived for
11    let struct_name = &input.ident;
12
13    // Generate the implementation of CcanvasConfig trait
14    let expanded = quote! {
15        impl CcanvasConfig for #struct_name {
16            const CNAME: &'static str = env!("CARGO_PKG_NAME");
17        }
18    };
19
20    // Convert the expanded tokens back into a TokenStream and return it
21    TokenStream::from(expanded)
22}