events: Remove some needless Result wrapping
This commit is contained in:
parent
4c41bfd1f3
commit
ee6d258bdf
@ -41,10 +41,8 @@ pub fn expand_event(input: DeriveInput) -> syn::Result<TokenStream> {
|
|||||||
));
|
));
|
||||||
};
|
};
|
||||||
|
|
||||||
let serialize_impl = expand_serialize_event(&input, &var, &fields, &import_path)?;
|
let serialize_impl = expand_serialize_event(&input, &var, &fields, &import_path);
|
||||||
|
let deserialize_impl = expand_deserialize_event(&input, &var, &fields, &import_path);
|
||||||
let deserialize_impl = expand_deserialize_event(&input, &var, &fields, &import_path)?;
|
|
||||||
|
|
||||||
let conversion_impl = expand_from_into(&input, &kind, &var, &fields, &import_path);
|
let conversion_impl = expand_from_into(&input, &kind, &var, &fields, &import_path);
|
||||||
|
|
||||||
let eq_impl = expand_eq_ord_event(&input, &fields);
|
let eq_impl = expand_eq_ord_event(&input, &fields);
|
||||||
@ -65,7 +63,7 @@ fn expand_serialize_event(
|
|||||||
var: &EventKindVariation,
|
var: &EventKindVariation,
|
||||||
fields: &[Field],
|
fields: &[Field],
|
||||||
import_path: &TokenStream,
|
import_path: &TokenStream,
|
||||||
) -> syn::Result<TokenStream> {
|
) -> TokenStream {
|
||||||
let ident = &input.ident;
|
let ident = &input.ident;
|
||||||
let (impl_gen, ty_gen, where_clause) = input.generics.split_for_impl();
|
let (impl_gen, ty_gen, where_clause) = input.generics.split_for_impl();
|
||||||
let serialize_fields = fields
|
let serialize_fields = fields
|
||||||
@ -109,7 +107,7 @@ fn expand_serialize_event(
|
|||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
Ok(quote! {
|
quote! {
|
||||||
impl #impl_gen #import_path::exports::serde::ser::Serialize for #ident #ty_gen #where_clause {
|
impl #impl_gen #import_path::exports::serde::ser::Serialize for #ident #ty_gen #where_clause {
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
where
|
where
|
||||||
@ -126,7 +124,7 @@ fn expand_serialize_event(
|
|||||||
state.end()
|
state.end()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expand_deserialize_event(
|
fn expand_deserialize_event(
|
||||||
@ -134,7 +132,7 @@ fn expand_deserialize_event(
|
|||||||
var: &EventKindVariation,
|
var: &EventKindVariation,
|
||||||
fields: &[Field],
|
fields: &[Field],
|
||||||
import_path: &TokenStream,
|
import_path: &TokenStream,
|
||||||
) -> syn::Result<TokenStream> {
|
) -> TokenStream {
|
||||||
let ident = &input.ident;
|
let ident = &input.ident;
|
||||||
// we know there is a content field already
|
// we know there is a content field already
|
||||||
let content_type = fields
|
let content_type = fields
|
||||||
@ -265,7 +263,7 @@ fn expand_deserialize_event(
|
|||||||
quote! {}
|
quote! {}
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(quote! {
|
quote! {
|
||||||
impl #deserialize_impl_gen #import_path::exports::serde::de::Deserialize<'de> for #ident #ty_gen #where_clause {
|
impl #deserialize_impl_gen #import_path::exports::serde::de::Deserialize<'de> for #ident #ty_gen #where_clause {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
where
|
where
|
||||||
@ -344,7 +342,7 @@ fn expand_deserialize_event(
|
|||||||
deserializer.deserialize_map(EventVisitor(#deserialize_phantom_type))
|
deserializer.deserialize_map(EventVisitor(#deserialize_phantom_type))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expand_from_into(
|
fn expand_from_into(
|
||||||
|
@ -754,8 +754,7 @@ fn redacted_accessor_methods(
|
|||||||
variants: &[EventEnumVariant],
|
variants: &[EventEnumVariant],
|
||||||
import_path: &TokenStream,
|
import_path: &TokenStream,
|
||||||
) -> Option<TokenStream> {
|
) -> Option<TokenStream> {
|
||||||
// this will never fail as it is called in `expand_any_with_deser`.
|
let ident = kind.to_event_enum_ident(var)?;
|
||||||
let ident = kind.to_event_enum_ident(var).unwrap();
|
|
||||||
let methods = EVENT_FIELDS.iter().map(|(name, has_field)| {
|
let methods = EVENT_FIELDS.iter().map(|(name, has_field)| {
|
||||||
generate_accessor(name, kind, var, *has_field, variants, import_path)
|
generate_accessor(name, kind, var, *has_field, variants, import_path)
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user