mirror of
https://github.com/serde-rs/serde.git
synced 2025-10-01 15:01:49 +00:00
Format with rustfmt 0.99.1
This commit is contained in:
parent
5fff0d936d
commit
28db9d4989
@ -32,8 +32,7 @@ pub fn without_defaults(generics: &syn::Generics) -> syn::Generics {
|
|||||||
..param.clone()
|
..param.clone()
|
||||||
}),
|
}),
|
||||||
_ => param.clone(),
|
_ => param.clone(),
|
||||||
})
|
}).collect(),
|
||||||
.collect(),
|
|
||||||
..generics.clone()
|
..generics.clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -193,8 +192,7 @@ pub fn with_bound(
|
|||||||
.map(|id| syn::TypePath {
|
.map(|id| syn::TypePath {
|
||||||
qself: None,
|
qself: None,
|
||||||
path: id.into(),
|
path: id.into(),
|
||||||
})
|
}).chain(associated_type_usage.into_iter().cloned())
|
||||||
.chain(associated_type_usage.into_iter().cloned())
|
|
||||||
.map(|bounded_ty| {
|
.map(|bounded_ty| {
|
||||||
syn::WherePredicate::Type(syn::PredicateType {
|
syn::WherePredicate::Type(syn::PredicateType {
|
||||||
lifetimes: None,
|
lifetimes: None,
|
||||||
@ -208,7 +206,7 @@ pub fn with_bound(
|
|||||||
lifetimes: None,
|
lifetimes: None,
|
||||||
path: bound.clone(),
|
path: bound.clone(),
|
||||||
})].into_iter()
|
})].into_iter()
|
||||||
.collect(),
|
.collect(),
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -241,7 +239,7 @@ pub fn with_self_bound(
|
|||||||
lifetimes: None,
|
lifetimes: None,
|
||||||
path: bound.clone(),
|
path: bound.clone(),
|
||||||
})].into_iter()
|
})].into_iter()
|
||||||
.collect(),
|
.collect(),
|
||||||
}));
|
}));
|
||||||
generics
|
generics
|
||||||
}
|
}
|
||||||
@ -270,8 +268,7 @@ pub fn with_lifetime_bound(generics: &syn::Generics, lifetime: &str) -> syn::Gen
|
|||||||
syn::GenericParam::Const(_) => {}
|
syn::GenericParam::Const(_) => {}
|
||||||
}
|
}
|
||||||
param
|
param
|
||||||
}))
|
})).collect();
|
||||||
.collect();
|
|
||||||
|
|
||||||
syn::Generics {
|
syn::Generics {
|
||||||
params: params,
|
params: params,
|
||||||
@ -307,13 +304,12 @@ fn type_of_item(cont: &Container) -> syn::Type {
|
|||||||
syn::GenericParam::Const(_) => {
|
syn::GenericParam::Const(_) => {
|
||||||
panic!("Serde does not support const generics yet");
|
panic!("Serde does not support const generics yet");
|
||||||
}
|
}
|
||||||
})
|
}).collect(),
|
||||||
.collect(),
|
|
||||||
gt_token: <Token![>]>::default(),
|
gt_token: <Token![>]>::default(),
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
}].into_iter()
|
}].into_iter()
|
||||||
.collect(),
|
.collect(),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -204,7 +204,9 @@ fn build_generics(cont: &Container, borrowed: &BorrowedLifetimes) -> syn::Generi
|
|||||||
// All other fields may need a `T: Deserialize` bound where T is the type of the
|
// All other fields may need a `T: Deserialize` bound where T is the type of the
|
||||||
// field.
|
// field.
|
||||||
fn needs_deserialize_bound(field: &attr::Field, variant: Option<&attr::Variant>) -> bool {
|
fn needs_deserialize_bound(field: &attr::Field, variant: Option<&attr::Variant>) -> bool {
|
||||||
!field.skip_deserializing() && field.deserialize_with().is_none() && field.de_bound().is_none()
|
!field.skip_deserializing()
|
||||||
|
&& field.deserialize_with().is_none()
|
||||||
|
&& field.de_bound().is_none()
|
||||||
&& variant.map_or(true, |variant| {
|
&& variant.map_or(true, |variant| {
|
||||||
!variant.skip_deserializing()
|
!variant.skip_deserializing()
|
||||||
&& variant.deserialize_with().is_none()
|
&& variant.deserialize_with().is_none()
|
||||||
@ -1350,8 +1352,7 @@ fn deserialize_adjacently_tagged_enum(
|
|||||||
quote! {
|
quote! {
|
||||||
__Field::#variant_index => #block
|
__Field::#variant_index => #block
|
||||||
}
|
}
|
||||||
})
|
}).collect();
|
||||||
.collect();
|
|
||||||
|
|
||||||
let expecting = format!("adjacently tagged enum {}", params.type_name());
|
let expecting = format!("adjacently tagged enum {}", params.type_name());
|
||||||
let type_name = cattrs.name().deserialize_name();
|
let type_name = cattrs.name().deserialize_name();
|
||||||
@ -1939,8 +1940,7 @@ fn deserialize_custom_identifier(
|
|||||||
variant.attrs.name().deserialize_name(),
|
variant.attrs.name().deserialize_name(),
|
||||||
variant.ident.clone(),
|
variant.ident.clone(),
|
||||||
)
|
)
|
||||||
})
|
}).collect();
|
||||||
.collect();
|
|
||||||
|
|
||||||
let names = names_idents.iter().map(|&(ref name, _)| name);
|
let names = names_idents.iter().map(|&(ref name, _)| name);
|
||||||
|
|
||||||
|
@ -129,8 +129,7 @@ fn enum_from_ast<'a>(
|
|||||||
style: style,
|
style: style,
|
||||||
fields: fields,
|
fields: fields,
|
||||||
}
|
}
|
||||||
})
|
}).collect()
|
||||||
.collect()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn struct_from_ast<'a>(
|
fn struct_from_ast<'a>(
|
||||||
@ -173,6 +172,5 @@ fn fields_from_ast<'a>(
|
|||||||
attrs: attr::Field::from_ast(cx, i, field, attrs, container_default),
|
attrs: attr::Field::from_ast(cx, i, field, attrs, container_default),
|
||||||
ty: &field.ty,
|
ty: &field.ty,
|
||||||
original: field,
|
original: field,
|
||||||
})
|
}).collect()
|
||||||
.collect()
|
|
||||||
}
|
}
|
||||||
|
@ -62,8 +62,7 @@ fn pretend_fields_used(cont: &Container) -> TokenStream {
|
|||||||
Some(quote!(#type_ident::#variant_ident #pat))
|
Some(quote!(#type_ident::#variant_ident #pat))
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
}).collect::<Vec<_>>(),
|
||||||
.collect::<Vec<_>>(),
|
|
||||||
Data::Struct(Style::Struct, ref fields) => {
|
Data::Struct(Style::Struct, ref fields) => {
|
||||||
let pat = struct_pattern(fields);
|
let pat = struct_pattern(fields);
|
||||||
vec![quote!(#type_ident #pat)]
|
vec![quote!(#type_ident #pat)]
|
||||||
|
@ -160,7 +160,9 @@ fn build_generics(cont: &Container) -> syn::Generics {
|
|||||||
// attribute specify their own bound so we do not generate one. All other fields
|
// attribute specify their own bound so we do not generate one. All other fields
|
||||||
// may need a `T: Serialize` bound where T is the type of the field.
|
// may need a `T: Serialize` bound where T is the type of the field.
|
||||||
fn needs_serialize_bound(field: &attr::Field, variant: Option<&attr::Variant>) -> bool {
|
fn needs_serialize_bound(field: &attr::Field, variant: Option<&attr::Variant>) -> bool {
|
||||||
!field.skip_serializing() && field.serialize_with().is_none() && field.ser_bound().is_none()
|
!field.skip_serializing()
|
||||||
|
&& field.serialize_with().is_none()
|
||||||
|
&& field.ser_bound().is_none()
|
||||||
&& variant.map_or(true, |variant| {
|
&& variant.map_or(true, |variant| {
|
||||||
!variant.skip_serializing()
|
!variant.skip_serializing()
|
||||||
&& variant.serialize_with().is_none()
|
&& variant.serialize_with().is_none()
|
||||||
@ -282,8 +284,7 @@ fn serialize_tuple_struct(
|
|||||||
let field_expr = get_member(params, field, &Member::Unnamed(index));
|
let field_expr = get_member(params, field, &Member::Unnamed(index));
|
||||||
quote!(if #path(#field_expr) { 0 } else { 1 })
|
quote!(if #path(#field_expr) { 0 } else { 1 })
|
||||||
}
|
}
|
||||||
})
|
}).fold(quote!(0), |sum, expr| quote!(#sum + #expr));
|
||||||
.fold(quote!(0), |sum, expr| quote!(#sum + #expr));
|
|
||||||
|
|
||||||
quote_block! {
|
quote_block! {
|
||||||
let #let_mut __serde_state = try!(_serde::Serializer::serialize_tuple_struct(__serializer, #type_name, #len));
|
let #let_mut __serde_state = try!(_serde::Serializer::serialize_tuple_struct(__serializer, #type_name, #len));
|
||||||
@ -326,8 +327,7 @@ fn serialize_struct_as_struct(
|
|||||||
let field_expr = get_member(params, field, &field.member);
|
let field_expr = get_member(params, field, &field.member);
|
||||||
quote!(if #path(#field_expr) { 0 } else { 1 })
|
quote!(if #path(#field_expr) { 0 } else { 1 })
|
||||||
}
|
}
|
||||||
})
|
}).fold(quote!(0), |sum, expr| quote!(#sum + #expr));
|
||||||
.fold(quote!(0), |sum, expr| quote!(#sum + #expr));
|
|
||||||
|
|
||||||
quote_block! {
|
quote_block! {
|
||||||
let #let_mut __serde_state = try!(_serde::Serializer::serialize_struct(__serializer, #type_name, #len));
|
let #let_mut __serde_state = try!(_serde::Serializer::serialize_struct(__serializer, #type_name, #len));
|
||||||
@ -361,8 +361,7 @@ fn serialize_struct_as_map(
|
|||||||
let field_expr = get_member(params, field, &field.member);
|
let field_expr = get_member(params, field, &field.member);
|
||||||
quote!(if #path(#field_expr) { 0 } else { 1 })
|
quote!(if #path(#field_expr) { 0 } else { 1 })
|
||||||
}
|
}
|
||||||
})
|
}).fold(quote!(0), |sum, expr| quote!(#sum + #expr));
|
||||||
.fold(quote!(0), |sum, expr| quote!(#sum + #expr));
|
|
||||||
quote!(_serde::export::Some(#len))
|
quote!(_serde::export::Some(#len))
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -383,8 +382,7 @@ fn serialize_enum(params: &Parameters, variants: &[Variant], cattrs: &attr::Cont
|
|||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(variant_index, variant)| {
|
.map(|(variant_index, variant)| {
|
||||||
serialize_variant(params, variant, variant_index as u32, cattrs)
|
serialize_variant(params, variant, variant_index as u32, cattrs)
|
||||||
})
|
}).collect();
|
||||||
.collect();
|
|
||||||
|
|
||||||
quote_expr! {
|
quote_expr! {
|
||||||
match *#self_var {
|
match *#self_var {
|
||||||
@ -788,8 +786,7 @@ fn serialize_tuple_variant(
|
|||||||
let field_expr = Ident::new(&format!("__field{}", i), Span::call_site());
|
let field_expr = Ident::new(&format!("__field{}", i), Span::call_site());
|
||||||
quote!(if #path(#field_expr) { 0 } else { 1 })
|
quote!(if #path(#field_expr) { 0 } else { 1 })
|
||||||
}
|
}
|
||||||
})
|
}).fold(quote!(0), |sum, expr| quote!(#sum + #expr));
|
||||||
.fold(quote!(0), |sum, expr| quote!(#sum + #expr));
|
|
||||||
|
|
||||||
match context {
|
match context {
|
||||||
TupleVariant::ExternallyTagged {
|
TupleVariant::ExternallyTagged {
|
||||||
@ -866,8 +863,7 @@ fn serialize_struct_variant<'a>(
|
|||||||
Some(path) => quote!(if #path(#member) { 0 } else { 1 }),
|
Some(path) => quote!(if #path(#member) { 0 } else { 1 }),
|
||||||
None => quote!(1),
|
None => quote!(1),
|
||||||
}
|
}
|
||||||
})
|
}).fold(quote!(0), |sum, expr| quote!(#sum + #expr));
|
||||||
.fold(quote!(0), |sum, expr| quote!(#sum + #expr));
|
|
||||||
|
|
||||||
match context {
|
match context {
|
||||||
StructVariant::ExternallyTagged {
|
StructVariant::ExternallyTagged {
|
||||||
@ -1046,8 +1042,7 @@ fn serialize_tuple_struct_visitor(
|
|||||||
None => ser,
|
None => ser,
|
||||||
Some(skip) => quote!(if !#skip { #ser }),
|
Some(skip) => quote!(if !#skip { #ser }),
|
||||||
}
|
}
|
||||||
})
|
}).collect()
|
||||||
.collect()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_struct_visitor(
|
fn serialize_struct_visitor(
|
||||||
@ -1141,8 +1136,7 @@ fn wrap_serialize_variant_with(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
quote!(#id)
|
quote!(#id)
|
||||||
})
|
}).collect();
|
||||||
.collect();
|
|
||||||
wrap_serialize_with(
|
wrap_serialize_with(
|
||||||
params,
|
params,
|
||||||
serialize_with,
|
serialize_with,
|
||||||
|
@ -218,9 +218,9 @@ fn assert_de_tokens_ignore(ignorable_tokens: &[Token]) {
|
|||||||
Token::I32(1),
|
Token::I32(1),
|
||||||
Token::Str("ignored"),
|
Token::Str("ignored"),
|
||||||
].into_iter()
|
].into_iter()
|
||||||
.chain(ignorable_tokens.to_vec().into_iter())
|
.chain(ignorable_tokens.to_vec().into_iter())
|
||||||
.chain(vec![Token::MapEnd].into_iter())
|
.chain(vec![Token::MapEnd].into_iter())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let mut de = serde_test::Deserializer::new(&concated_tokens);
|
let mut de = serde_test::Deserializer::new(&concated_tokens);
|
||||||
let base = IgnoreBase::deserialize(&mut de).unwrap();
|
let base = IgnoreBase::deserialize(&mut de).unwrap();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user