/// Code generator for implementing the [cachem::Parse] trait
///
/// # Params
///
/// * `input` - Input of the struct where the trait should be implemented only
///
/// # Returns
///
/// [proc_macro2::TokenStream] with the implementation of the [cachem::Parse]
/// trait.
///
Code generator for implementing the [cachem::Parse] trait
Code generator for implementing the [ cachem :: Parse ] trait
pub fn code_gen(input: DeriveInput) -> TokenStream {
    let name = input.ident;
    let fn_read  = crate::parse::generate_fn_read(&name, &input.data);
    let fn_write = crate::parse::generate_fn_write(&name, &input.data);
    let generics = input.generics;
    let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
    quote! {
        #[async_trait::async_trait]
        impl #impl_generics cachem::Parse for #name #ty_generics #where_clause {
            async fn read<B>(
                buf: &mut B
            ) -> Result<Self, cachem::CachemError>
            where
                B: tokio::io::AsyncBufRead + tokio::io::AsyncRead + Send + Unpin {
                #fn_read
            }
            async fn write<B>(
                &self,
                buf: &mut B
            ) -> Result<(), cachem::CachemError>
            where
                B: tokio::io::AsyncWrite + Send + Unpin {
                #fn_write
                Ok(())
            }
        }
    }
}
pub fn code_gen ( input : DeriveInput ) -> TokenStream { let name = input . ident ; let fn_read = crate :: parse :: generate_fn_read ( & name , & input . data ) ; let fn_write = crate :: parse :: generate_fn_write ( & name , & input . data ) ; let generics = input . generics ; let ( impl_generics , ty_generics , where_clause ) = generics . split_for_impl ( ) ; quote ! { [ async_trait async_trait ] impl impl_generics cachem Parse for name ty_generics where_clause { async fn read B ( buf mut B ) Result Self cachem CachemError where B tokio io AsyncBufRead tokio io AsyncRead Send Unpin { fn_read } async fn write B ( self buf mut B ) Result ( ) cachem CachemError where B tokio io AsyncWrite Send Unpin { fn_write Ok ( ( ) ) } } } }
Code generator for implementing the [cachem::Parse] trait
Code generator for implementing the [ cachem :: Parse ] trait
[proc_macro2::TokenStream] with the implementation of the [cachem::Parse]
trait.
[ proc_macro2 :: TokenStream ] with the implementation of the [ cachem :: Parse ] trait .
input
DeriveInput
params
`input` - Input of the struct where the trait should be implemented only
` input ` - Input of the struct where the trait should be implemented only