Simplify named field handling code
This commit is contained in:
parent
c15a0a985c
commit
cd7e3b4224
|
@ -190,15 +190,12 @@ fn deserialize_struct(
|
||||||
let mut declare_values = TokenStream::new();
|
let mut declare_values = TokenStream::new();
|
||||||
let mut return_val = TokenStream::new();
|
let mut return_val = TokenStream::new();
|
||||||
|
|
||||||
match data.fields {
|
match &data.fields {
|
||||||
syn::Fields::Named(ref fields) => {
|
syn::Fields::Named(fields) => {
|
||||||
fields.named.iter().enumerate().for_each(|(index, field)| {
|
for (index, field) in fields.named.iter().enumerate() {
|
||||||
let field_meta = match FieldMeta::from_field(field, &container_meta) {
|
let field_meta = match FieldMeta::from_field(field, &container_meta) {
|
||||||
Ok(meta) => meta,
|
Ok(meta) => meta,
|
||||||
Err(err) => {
|
Err(err) => return err.into_compile_error(),
|
||||||
return_val.extend(err.into_compile_error());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let tokens = match field_meta.attribute {
|
let tokens = match field_meta.attribute {
|
||||||
|
@ -206,7 +203,7 @@ fn deserialize_struct(
|
||||||
false => &mut elements_tokens,
|
false => &mut elements_tokens,
|
||||||
};
|
};
|
||||||
|
|
||||||
process_field(
|
named_field(
|
||||||
field,
|
field,
|
||||||
index,
|
index,
|
||||||
&mut declare_values,
|
&mut declare_values,
|
||||||
|
@ -215,7 +212,7 @@ fn deserialize_struct(
|
||||||
field_meta,
|
field_meta,
|
||||||
&container_meta,
|
&container_meta,
|
||||||
);
|
);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
syn::Fields::Unnamed(_) => panic!("unamed"),
|
syn::Fields::Unnamed(_) => panic!("unamed"),
|
||||||
syn::Fields::Unit => {}
|
syn::Fields::Unit => {}
|
||||||
|
@ -312,7 +309,7 @@ fn deserialize_struct(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn process_field(
|
fn named_field(
|
||||||
field: &syn::Field,
|
field: &syn::Field,
|
||||||
index: usize,
|
index: usize,
|
||||||
declare_values: &mut TokenStream,
|
declare_values: &mut TokenStream,
|
||||||
|
|
|
@ -180,10 +180,10 @@ fn serialize_struct(
|
||||||
let mut body = TokenStream::new();
|
let mut body = TokenStream::new();
|
||||||
let mut attributes = TokenStream::new();
|
let mut attributes = TokenStream::new();
|
||||||
|
|
||||||
match data.fields {
|
match &data.fields {
|
||||||
syn::Fields::Named(ref fields) => {
|
syn::Fields::Named(fields) => {
|
||||||
for field in &fields.named {
|
for field in &fields.named {
|
||||||
if let Err(err) = process_named_field(field, &mut body, &mut attributes, &meta) {
|
if let Err(err) = named_field(field, &mut body, &mut attributes, &meta) {
|
||||||
return err.to_compile_error();
|
return err.to_compile_error();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -252,7 +252,7 @@ fn serialize_struct(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_named_field(
|
fn named_field(
|
||||||
field: &syn::Field,
|
field: &syn::Field,
|
||||||
body: &mut TokenStream,
|
body: &mut TokenStream,
|
||||||
attributes: &mut TokenStream,
|
attributes: &mut TokenStream,
|
||||||
|
|
Loading…
Reference in New Issue