microrm-macros 0.6.3

Procedural macro implementations for the microrm crate.
Documentation
use quote::quote;

pub fn derive(tokens: proc_macro::TokenStream) -> proc_macro::TokenStream {
    let input: syn::DeriveInput = syn::parse_macro_input!(tokens);

    let ident = input.ident;

    quote!{
        impl ::microrm::schema::datum::OwnedDatum for #ident {
            type RefData<'l> = &'l Self where Self: 'l;
            fn as_ref(&self) -> &#ident {
                &self
            }
        }
        impl<'l> ::microrm::schema::datum::BorrowedDatum<'l, #ident> for #ident {
            fn as_owned(&self) -> #ident {
                self.clone()
            }
        }
        impl ::microrm::schema::datum::Datum for #ident {
            fn sql_type() -> &'static str {
                <::microrm::Serialized< #ident > as ::microrm::schema::datum::Datum>::sql_type()
            }
            fn bind_to(&self, stmt: &mut ::microrm::db::StatementContext, index: i32) -> ::microrm::DBResult<()> {
                self.clone().into_serialized().bind_to(stmt, index)
            }
            fn build_from(rdata: ::microrm::schema::relation::RelationData, stmt: &mut ::microrm::db::StatementRow, index: &mut i32) -> ::microrm::DBResult<Self>
            where
                Self: Sized,
            {
                <::microrm::Serialized< #ident > as ::microrm::schema::datum::Datum>::build_from(rdata, stmt, index).map(::microrm::Serialized::wrapped)
            }

            fn accept_discriminator(d: &mut impl ::microrm::schema::datum::DatumDiscriminator) where Self: Sized {
                d.visit_value::<Self>();
            }
            fn accept_discriminator_ref(&self, d: &mut impl ::microrm::schema::datum::DatumDiscriminatorRef) where Self: Sized {
                d.visit_value::<Self>(self);
            }
        }
    }.into()
}