Skip to main content

cib_derive/
lib.rs

1use proc_macro::TokenStream;
2use quote::quote;
3use syn::parse_macro_input;
4
5/// Derive macro for `Cib` trait. Generates a trivial impl that treats the
6/// owned type as itself (moves when owned). For a type `T`, this expands to:
7#[proc_macro_derive(Cib)]
8pub fn derive_cib(input: TokenStream) -> TokenStream {
9    let input = parse_macro_input!(input as syn::DeriveInput);
10    let name = input.ident;
11    let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
12
13    let expanded = quote! {
14        impl #impl_generics ::cib::Cib<Self> for #name #ty_generics #where_clause {
15            fn cib(self) -> Self { self }
16        }
17    };
18
19    expanded.into()
20}