pub fn expand_event(input: DeriveInput) -> syn::Result<TokenStream> {
    let ruma_events = import_ruma_events();

    let ident = &input.ident;
    let (kind, var) = to_kind_variation(ident).ok_or_else(|| {
        syn::Error::new_spanned(ident, "not a valid ruma event struct identifier")
    })?;

    let fields: Vec<_> = if let Data::Struct(DataStruct { fields, .. }) = input.data.clone() {
        if let Fields::Named(FieldsNamed { named, .. }) = fields {
            if !named.iter().any(|f| f.ident.as_ref().unwrap() == "content") {
                return Err(syn::Error::new(
                    Span::call_site(),
                    "struct must contain a `content` field",
                ));
            }

            named.into_iter().collect()
        } else {
            return Err(syn::Error::new_spanned(
                fields,
                "the `Event` derive only supports named fields",
            ));
        }
    } else {
        return Err(syn::Error::new_spanned(
            input.ident,
            "the `Event` derive only supports structs with named fields",
        ));
    };

    let serialize_impl = expand_serialize_event(&input, &var, &fields, &ruma_events);
    let deserialize_impl = expand_deserialize_event(&input, &var, &fields, &ruma_events)?;
    let conversion_impl = expand_from_into(&input, &kind, &var, &fields, &ruma_events);

    let eq_impl = expand_eq_ord_event(&input, &fields);

    Ok(quote! {
        #conversion_impl
        #serialize_impl
        #deserialize_impl
        #eq_impl
    })
}
/// Derive `Event` macro code generation.
Derive `Event` macro code generation.
Derive ` Event ` macro code generation .
pub fn expand_event(input: DeriveInput) -> syn::Result<TokenStream> {
    let ruma_events = import_ruma_events();
    let ident = &input.ident;
    let (kind, var) = to_kind_variation(ident).ok_or_else(|| {
        syn::Error::new_spanned(ident, "not a valid ruma event struct identifier")
    })?;
    let fields: Vec<_> = if let Data::Struct(DataStruct { fields, .. }) = input.data.clone() {
        if let Fields::Named(FieldsNamed { named, .. }) = fields {
            if !named.iter().any(|f| f.ident.as_ref().unwrap() == "content") {
                return Err(syn::Error::new(
                    Span::call_site(),
                    "struct must contain a `content` field",
                ));
            }
            named.into_iter().collect()
        } else {
            return Err(syn::Error::new_spanned(
                fields,
                "the `Event` derive only supports named fields",
            ));
        }
    } else {
        return Err(syn::Error::new_spanned(
            input.ident,
            "the `Event` derive only supports structs with named fields",
        ));
    };
    let serialize_impl = expand_serialize_event(&input, &var, &fields, &ruma_events);
    let deserialize_impl = expand_deserialize_event(&input, &var, &fields, &ruma_events)?;
    let conversion_impl = expand_from_into(&input, &kind, &var, &fields, &ruma_events);
    let eq_impl = expand_eq_ord_event(&input, &fields);
    Ok(quote! {
        #conversion_impl
        #serialize_impl
        #deserialize_impl
        #eq_impl
    })
}
pub fn expand_event ( input : DeriveInput ) -> syn :: Result < TokenStream > { let ruma_events = import_ruma_events ( ) ; let ident = & input . ident ; let ( kind , var ) = to_kind_variation ( ident ) . ok_or_else ( | | { syn :: Error :: new_spanned ( ident , " " ) } ) ? ; let fields : Vec < _ > = if let Data :: Struct ( DataStruct { fields , .. } ) = input . data . clone ( ) { if let Fields :: Named ( FieldsNamed { named , .. } ) = fields { if ! named . iter ( ) . any ( | f | f . ident . as_ref ( ) . unwrap ( ) == " " ) { return Err ( syn :: Error :: new ( Span :: call_site ( ) , " " , ) ) ; } named . into_iter ( ) . collect ( ) } else { return Err ( syn :: Error :: new_spanned ( fields , " " , ) ) ; } } else { return Err ( syn :: Error :: new_spanned ( input . ident , " " , ) ) ; } ; let serialize_impl = expand_serialize_event ( & input , & var , & fields , & ruma_events ) ; let deserialize_impl = expand_deserialize_event ( & input , & var , & fields , & ruma_events ) ? ; let conversion_impl = expand_from_into ( & input , & kind , & var , & fields , & ruma_events ) ; let eq_impl = expand_eq_ord_event ( & input , & fields ) ; Ok ( quote ! { conversion_impl serialize_impl deserialize_impl eq_impl } ) }
Derive `Event` macro code generation.
Derive ` Event ` macro code generation .
input
DeriveInput