mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-13 14:51:01 +00:00
Remove use of ref keyword from serde_derive
This commit is contained in:
+15
-15
@@ -17,8 +17,8 @@ pub fn without_defaults(generics: &syn::Generics) -> syn::Generics {
|
|||||||
params: generics
|
params: generics
|
||||||
.params
|
.params
|
||||||
.iter()
|
.iter()
|
||||||
.map(|param| match *param {
|
.map(|param| match param {
|
||||||
syn::GenericParam::Type(ref param) => syn::GenericParam::Type(syn::TypeParam {
|
syn::GenericParam::Type(param) => syn::GenericParam::Type(syn::TypeParam {
|
||||||
eq_token: None,
|
eq_token: None,
|
||||||
default: None,
|
default: None,
|
||||||
..param.clone()
|
..param.clone()
|
||||||
@@ -63,8 +63,8 @@ pub fn with_where_predicates_from_variants(
|
|||||||
generics: &syn::Generics,
|
generics: &syn::Generics,
|
||||||
from_variant: fn(&attr::Variant) -> Option<&[syn::WherePredicate]>,
|
from_variant: fn(&attr::Variant) -> Option<&[syn::WherePredicate]>,
|
||||||
) -> syn::Generics {
|
) -> syn::Generics {
|
||||||
let variants = match cont.data {
|
let variants = match &cont.data {
|
||||||
Data::Enum(ref variants) => variants,
|
Data::Enum(variants) => variants,
|
||||||
Data::Struct(_, _) => {
|
Data::Struct(_, _) => {
|
||||||
return generics.clone();
|
return generics.clone();
|
||||||
}
|
}
|
||||||
@@ -114,8 +114,8 @@ pub fn with_bound(
|
|||||||
}
|
}
|
||||||
impl<'ast> Visit<'ast> for FindTyParams<'ast> {
|
impl<'ast> Visit<'ast> for FindTyParams<'ast> {
|
||||||
fn visit_field(&mut self, field: &'ast syn::Field) {
|
fn visit_field(&mut self, field: &'ast syn::Field) {
|
||||||
if let syn::Type::Path(ref ty) = field.ty {
|
if let syn::Type::Path(ty) = &field.ty {
|
||||||
if let Some(Pair::Punctuated(ref t, _)) = ty.path.segments.pairs().next() {
|
if let Some(Pair::Punctuated(t, _)) = ty.path.segments.pairs().next() {
|
||||||
if self.all_type_params.contains(&t.ident) {
|
if self.all_type_params.contains(&t.ident) {
|
||||||
self.associated_type_usage.push(ty);
|
self.associated_type_usage.push(ty);
|
||||||
}
|
}
|
||||||
@@ -160,8 +160,8 @@ pub fn with_bound(
|
|||||||
relevant_type_params: HashSet::new(),
|
relevant_type_params: HashSet::new(),
|
||||||
associated_type_usage: Vec::new(),
|
associated_type_usage: Vec::new(),
|
||||||
};
|
};
|
||||||
match cont.data {
|
match &cont.data {
|
||||||
Data::Enum(ref variants) => {
|
Data::Enum(variants) => {
|
||||||
for variant in variants.iter() {
|
for variant in variants.iter() {
|
||||||
let relevant_fields = variant
|
let relevant_fields = variant
|
||||||
.fields
|
.fields
|
||||||
@@ -172,7 +172,7 @@ pub fn with_bound(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Data::Struct(_, ref fields) => {
|
Data::Struct(_, fields) => {
|
||||||
for field in fields.iter().filter(|field| filter(&field.attrs, None)) {
|
for field in fields.iter().filter(|field| filter(&field.attrs, None)) {
|
||||||
visitor.visit_field(field.original);
|
visitor.visit_field(field.original);
|
||||||
}
|
}
|
||||||
@@ -255,11 +255,11 @@ pub fn with_lifetime_bound(generics: &syn::Generics, lifetime: &str) -> syn::Gen
|
|||||||
let params = Some(syn::GenericParam::Lifetime(def))
|
let params = Some(syn::GenericParam::Lifetime(def))
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.chain(generics.params.iter().cloned().map(|mut param| {
|
.chain(generics.params.iter().cloned().map(|mut param| {
|
||||||
match param {
|
match &mut param {
|
||||||
syn::GenericParam::Lifetime(ref mut param) => {
|
syn::GenericParam::Lifetime(param) => {
|
||||||
param.bounds.push(bound.clone());
|
param.bounds.push(bound.clone());
|
||||||
}
|
}
|
||||||
syn::GenericParam::Type(ref mut param) => {
|
syn::GenericParam::Type(param) => {
|
||||||
param
|
param
|
||||||
.bounds
|
.bounds
|
||||||
.push(syn::TypeParamBound::Lifetime(bound.clone()));
|
.push(syn::TypeParamBound::Lifetime(bound.clone()));
|
||||||
@@ -291,14 +291,14 @@ fn type_of_item(cont: &Container) -> syn::Type {
|
|||||||
.generics
|
.generics
|
||||||
.params
|
.params
|
||||||
.iter()
|
.iter()
|
||||||
.map(|param| match *param {
|
.map(|param| match param {
|
||||||
syn::GenericParam::Type(ref param) => {
|
syn::GenericParam::Type(param) => {
|
||||||
syn::GenericArgument::Type(syn::Type::Path(syn::TypePath {
|
syn::GenericArgument::Type(syn::Type::Path(syn::TypePath {
|
||||||
qself: None,
|
qself: None,
|
||||||
path: param.ident.clone().into(),
|
path: param.ident.clone().into(),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
syn::GenericParam::Lifetime(ref param) => {
|
syn::GenericParam::Lifetime(param) => {
|
||||||
syn::GenericArgument::Lifetime(param.lifetime.clone())
|
syn::GenericArgument::Lifetime(param.lifetime.clone())
|
||||||
}
|
}
|
||||||
syn::GenericParam::Const(_) => {
|
syn::GenericParam::Const(_) => {
|
||||||
|
|||||||
+61
-66
@@ -75,7 +75,7 @@ fn precondition(cx: &Ctxt, cont: &Container) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn precondition_sized(cx: &Ctxt, cont: &Container) {
|
fn precondition_sized(cx: &Ctxt, cont: &Container) {
|
||||||
if let Data::Struct(_, ref fields) = cont.data {
|
if let Data::Struct(_, fields) = &cont.data {
|
||||||
if let Some(last) = fields.last() {
|
if let Some(last) = fields.last() {
|
||||||
if let syn::Type::Slice(_) = *last.ty {
|
if let syn::Type::Slice(_) = *last.ty {
|
||||||
cx.error_spanned_by(
|
cx.error_spanned_by(
|
||||||
@@ -229,8 +229,8 @@ impl BorrowedLifetimes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn de_lifetime_def(&self) -> Option<syn::LifetimeDef> {
|
fn de_lifetime_def(&self) -> Option<syn::LifetimeDef> {
|
||||||
match *self {
|
match self {
|
||||||
BorrowedLifetimes::Borrowed(ref bounds) => Some(syn::LifetimeDef {
|
BorrowedLifetimes::Borrowed(bounds) => Some(syn::LifetimeDef {
|
||||||
attrs: Vec::new(),
|
attrs: Vec::new(),
|
||||||
lifetime: syn::Lifetime::new("'de", Span::call_site()),
|
lifetime: syn::Lifetime::new("'de", Span::call_site()),
|
||||||
colon_token: None,
|
colon_token: None,
|
||||||
@@ -272,21 +272,19 @@ fn deserialize_body(cont: &Container, params: &Parameters) -> Fragment {
|
|||||||
} else if let Some(type_try_from) = cont.attrs.type_try_from() {
|
} else if let Some(type_try_from) = cont.attrs.type_try_from() {
|
||||||
deserialize_try_from(type_try_from)
|
deserialize_try_from(type_try_from)
|
||||||
} else if let attr::Identifier::No = cont.attrs.identifier() {
|
} else if let attr::Identifier::No = cont.attrs.identifier() {
|
||||||
match cont.data {
|
match &cont.data {
|
||||||
Data::Enum(ref variants) => deserialize_enum(params, variants, &cont.attrs),
|
Data::Enum(variants) => deserialize_enum(params, variants, &cont.attrs),
|
||||||
Data::Struct(Style::Struct, ref fields) => {
|
Data::Struct(Style::Struct, fields) => {
|
||||||
deserialize_struct(None, params, fields, &cont.attrs, None, &Untagged::No)
|
deserialize_struct(None, params, fields, &cont.attrs, None, &Untagged::No)
|
||||||
}
|
}
|
||||||
Data::Struct(Style::Tuple, ref fields) | Data::Struct(Style::Newtype, ref fields) => {
|
Data::Struct(Style::Tuple, fields) | Data::Struct(Style::Newtype, fields) => {
|
||||||
deserialize_tuple(None, params, fields, &cont.attrs, None)
|
deserialize_tuple(None, params, fields, &cont.attrs, None)
|
||||||
}
|
}
|
||||||
Data::Struct(Style::Unit, _) => deserialize_unit_struct(params, &cont.attrs),
|
Data::Struct(Style::Unit, _) => deserialize_unit_struct(params, &cont.attrs),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
match cont.data {
|
match &cont.data {
|
||||||
Data::Enum(ref variants) => {
|
Data::Enum(variants) => deserialize_custom_identifier(params, variants, &cont.attrs),
|
||||||
deserialize_custom_identifier(params, variants, &cont.attrs)
|
|
||||||
}
|
|
||||||
Data::Struct(_, _) => unreachable!("checked in serde_derive_internals"),
|
Data::Struct(_, _) => unreachable!("checked in serde_derive_internals"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -310,8 +308,8 @@ fn deserialize_in_place_body(cont: &Container, params: &Parameters) -> Option<St
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let code = match cont.data {
|
let code = match &cont.data {
|
||||||
Data::Struct(Style::Struct, ref fields) => {
|
Data::Struct(Style::Struct, fields) => {
|
||||||
if let Some(code) = deserialize_struct_in_place(None, params, fields, &cont.attrs, None)
|
if let Some(code) = deserialize_struct_in_place(None, params, fields, &cont.attrs, None)
|
||||||
{
|
{
|
||||||
code
|
code
|
||||||
@@ -319,7 +317,7 @@ fn deserialize_in_place_body(cont: &Container, params: &Parameters) -> Option<St
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Data::Struct(Style::Tuple, ref fields) | Data::Struct(Style::Newtype, ref fields) => {
|
Data::Struct(Style::Tuple, fields) | Data::Struct(Style::Newtype, fields) => {
|
||||||
deserialize_tuple_in_place(None, params, fields, &cont.attrs, None)
|
deserialize_tuple_in_place(None, params, fields, &cont.attrs, None)
|
||||||
}
|
}
|
||||||
Data::Enum(_) | Data::Struct(Style::Unit, _) => {
|
Data::Enum(_) | Data::Struct(Style::Unit, _) => {
|
||||||
@@ -348,8 +346,8 @@ fn deserialize_in_place_body(_cont: &Container, _params: &Parameters) -> Option<
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn deserialize_transparent(cont: &Container, params: &Parameters) -> Fragment {
|
fn deserialize_transparent(cont: &Container, params: &Parameters) -> Fragment {
|
||||||
let fields = match cont.data {
|
let fields = match &cont.data {
|
||||||
Data::Struct(_, ref fields) => fields,
|
Data::Struct(_, fields) => fields,
|
||||||
Data::Enum(_) => unreachable!(),
|
Data::Enum(_) => unreachable!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -369,9 +367,9 @@ fn deserialize_transparent(cont: &Container, params: &Parameters) -> Fragment {
|
|||||||
if field as *const Field == transparent_field as *const Field {
|
if field as *const Field == transparent_field as *const Field {
|
||||||
quote!(#member: __transparent)
|
quote!(#member: __transparent)
|
||||||
} else {
|
} else {
|
||||||
let value = match *field.attrs.default() {
|
let value = match field.attrs.default() {
|
||||||
attr::Default::Default => quote!(_serde::export::Default::default()),
|
attr::Default::Default => quote!(_serde::export::Default::default()),
|
||||||
attr::Default::Path(ref path) => quote!(#path()),
|
attr::Default::Path(path) => quote!(#path()),
|
||||||
attr::Default::None => quote!(_serde::export::PhantomData),
|
attr::Default::None => quote!(_serde::export::PhantomData),
|
||||||
};
|
};
|
||||||
quote!(#member: #value)
|
quote!(#member: #value)
|
||||||
@@ -456,7 +454,7 @@ fn deserialize_tuple(
|
|||||||
|
|
||||||
let is_enum = variant_ident.is_some();
|
let is_enum = variant_ident.is_some();
|
||||||
let type_path = match variant_ident {
|
let type_path = match variant_ident {
|
||||||
Some(ref variant_ident) => quote!(#construct::#variant_ident),
|
Some(variant_ident) => quote!(#construct::#variant_ident),
|
||||||
None => construct,
|
None => construct,
|
||||||
};
|
};
|
||||||
let expecting = match variant_ident {
|
let expecting = match variant_ident {
|
||||||
@@ -664,9 +662,9 @@ fn deserialize_seq(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let value_if_none = match *field.attrs.default() {
|
let value_if_none = match field.attrs.default() {
|
||||||
attr::Default::Default => quote!(_serde::export::Default::default()),
|
attr::Default::Default => quote!(_serde::export::Default::default()),
|
||||||
attr::Default::Path(ref path) => quote!(#path()),
|
attr::Default::Path(path) => quote!(#path()),
|
||||||
attr::Default::None => quote!(
|
attr::Default::None => quote!(
|
||||||
return _serde::export::Err(_serde::de::Error::invalid_length(#index_in_seq, &#expecting));
|
return _serde::export::Err(_serde::de::Error::invalid_length(#index_in_seq, &#expecting));
|
||||||
),
|
),
|
||||||
@@ -702,11 +700,11 @@ fn deserialize_seq(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let let_default = match *cattrs.default() {
|
let let_default = match cattrs.default() {
|
||||||
attr::Default::Default => Some(quote!(
|
attr::Default::Default => Some(quote!(
|
||||||
let __default: Self::Value = _serde::export::Default::default();
|
let __default: Self::Value = _serde::export::Default::default();
|
||||||
)),
|
)),
|
||||||
attr::Default::Path(ref path) => Some(quote!(
|
attr::Default::Path(path) => Some(quote!(
|
||||||
let __default: Self::Value = #path();
|
let __default: Self::Value = #path();
|
||||||
)),
|
)),
|
||||||
attr::Default::None => {
|
attr::Default::None => {
|
||||||
@@ -750,11 +748,11 @@ fn deserialize_seq_in_place(
|
|||||||
self.place.#member = #default;
|
self.place.#member = #default;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let value_if_none = match *field.attrs.default() {
|
let value_if_none = match field.attrs.default() {
|
||||||
attr::Default::Default => quote!(
|
attr::Default::Default => quote!(
|
||||||
self.place.#member = _serde::export::Default::default();
|
self.place.#member = _serde::export::Default::default();
|
||||||
),
|
),
|
||||||
attr::Default::Path(ref path) => quote!(
|
attr::Default::Path(path) => quote!(
|
||||||
self.place.#member = #path();
|
self.place.#member = #path();
|
||||||
),
|
),
|
||||||
attr::Default::None => quote!(
|
attr::Default::None => quote!(
|
||||||
@@ -793,11 +791,11 @@ fn deserialize_seq_in_place(
|
|||||||
|
|
||||||
let this = ¶ms.this;
|
let this = ¶ms.this;
|
||||||
let (_, ty_generics, _) = params.generics.split_for_impl();
|
let (_, ty_generics, _) = params.generics.split_for_impl();
|
||||||
let let_default = match *cattrs.default() {
|
let let_default = match cattrs.default() {
|
||||||
attr::Default::Default => Some(quote!(
|
attr::Default::Default => Some(quote!(
|
||||||
let __default: #this #ty_generics = _serde::export::Default::default();
|
let __default: #this #ty_generics = _serde::export::Default::default();
|
||||||
)),
|
)),
|
||||||
attr::Default::Path(ref path) => Some(quote!(
|
attr::Default::Path(path) => Some(quote!(
|
||||||
let __default: #this #ty_generics = #path();
|
let __default: #this #ty_generics = #path();
|
||||||
)),
|
)),
|
||||||
attr::Default::None => {
|
attr::Default::None => {
|
||||||
@@ -907,7 +905,7 @@ fn deserialize_struct(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let type_path = match variant_ident {
|
let type_path = match variant_ident {
|
||||||
Some(ref variant_ident) => quote!(#construct::#variant_ident),
|
Some(variant_ident) => quote!(#construct::#variant_ident),
|
||||||
None => construct,
|
None => construct,
|
||||||
};
|
};
|
||||||
let expecting = match variant_ident {
|
let expecting = match variant_ident {
|
||||||
@@ -1144,15 +1142,14 @@ fn deserialize_enum(
|
|||||||
variants: &[Variant],
|
variants: &[Variant],
|
||||||
cattrs: &attr::Container,
|
cattrs: &attr::Container,
|
||||||
) -> Fragment {
|
) -> Fragment {
|
||||||
match *cattrs.tag() {
|
match cattrs.tag() {
|
||||||
attr::TagType::External => deserialize_externally_tagged_enum(params, variants, cattrs),
|
attr::TagType::External => deserialize_externally_tagged_enum(params, variants, cattrs),
|
||||||
attr::TagType::Internal { ref tag } => {
|
attr::TagType::Internal { tag } => {
|
||||||
deserialize_internally_tagged_enum(params, variants, cattrs, tag)
|
deserialize_internally_tagged_enum(params, variants, cattrs, tag)
|
||||||
}
|
}
|
||||||
attr::TagType::Adjacent {
|
attr::TagType::Adjacent { tag, content } => {
|
||||||
ref tag,
|
deserialize_adjacently_tagged_enum(params, variants, cattrs, tag, content)
|
||||||
ref content,
|
}
|
||||||
} => deserialize_adjacently_tagged_enum(params, variants, cattrs, tag, content),
|
|
||||||
attr::TagType::None => deserialize_untagged_enum(params, variants, cattrs),
|
attr::TagType::None => deserialize_untagged_enum(params, variants, cattrs),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1174,12 +1171,10 @@ fn prepare_enum_variant_enum(
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let other_idx = variants
|
let other_idx = variants.iter().position(|variant| variant.attrs.other());
|
||||||
.iter()
|
|
||||||
.position(|ref variant| variant.attrs.other());
|
|
||||||
|
|
||||||
let variants_stmt = {
|
let variants_stmt = {
|
||||||
let variant_names = variant_names_idents.iter().map(|&(ref name, _, _)| name);
|
let variant_names = variant_names_idents.iter().map(|(name, _, _)| name);
|
||||||
quote! {
|
quote! {
|
||||||
const VARIANTS: &'static [&'static str] = &[ #(#variant_names),* ];
|
const VARIANTS: &'static [&'static str] = &[ #(#variant_names),* ];
|
||||||
}
|
}
|
||||||
@@ -1883,7 +1878,7 @@ fn deserialize_generated_identifier(
|
|||||||
other_idx: Option<usize>,
|
other_idx: Option<usize>,
|
||||||
) -> Fragment {
|
) -> Fragment {
|
||||||
let this = quote!(__Field);
|
let this = quote!(__Field);
|
||||||
let field_idents: &Vec<_> = &fields.iter().map(|&(_, ref ident, _)| ident).collect();
|
let field_idents: &Vec<_> = &fields.iter().map(|(_, ident, _)| ident).collect();
|
||||||
|
|
||||||
let (ignore_variant, fallthrough) = if !is_variant && cattrs.has_flatten() {
|
let (ignore_variant, fallthrough) = if !is_variant && cattrs.has_flatten() {
|
||||||
let ignore_variant = quote!(__other(_serde::private::de::Content<'de>),);
|
let ignore_variant = quote!(__other(_serde::private::de::Content<'de>),);
|
||||||
@@ -1989,7 +1984,7 @@ fn deserialize_custom_identifier(
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let names = names_idents.iter().map(|&(ref name, _, _)| name);
|
let names = names_idents.iter().map(|(name, _, _)| name);
|
||||||
|
|
||||||
let names_const = if fallthrough.is_some() {
|
let names_const = if fallthrough.is_some() {
|
||||||
None
|
None
|
||||||
@@ -2046,26 +2041,26 @@ fn deserialize_identifier(
|
|||||||
collect_other_fields: bool,
|
collect_other_fields: bool,
|
||||||
) -> Fragment {
|
) -> Fragment {
|
||||||
let mut flat_fields = Vec::new();
|
let mut flat_fields = Vec::new();
|
||||||
for &(_, ref ident, ref aliases) in fields {
|
for (_, ident, aliases) in fields {
|
||||||
flat_fields.extend(aliases.iter().map(|alias| (alias, ident)))
|
flat_fields.extend(aliases.iter().map(|alias| (alias, ident)))
|
||||||
}
|
}
|
||||||
|
|
||||||
let field_strs = flat_fields.iter().map(|&(ref name, _)| name);
|
let field_strs = flat_fields.iter().map(|(name, _)| name);
|
||||||
let field_borrowed_strs = flat_fields.iter().map(|&(ref name, _)| name);
|
let field_borrowed_strs = flat_fields.iter().map(|(name, _)| name);
|
||||||
let field_bytes = flat_fields
|
let field_bytes = flat_fields
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&(ref name, _)| Literal::byte_string(name.as_bytes()));
|
.map(|(name, _)| Literal::byte_string(name.as_bytes()));
|
||||||
let field_borrowed_bytes = flat_fields
|
let field_borrowed_bytes = flat_fields
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&(ref name, _)| Literal::byte_string(name.as_bytes()));
|
.map(|(name, _)| Literal::byte_string(name.as_bytes()));
|
||||||
|
|
||||||
let constructors: &Vec<_> = &flat_fields
|
let constructors: &Vec<_> = &flat_fields
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&(_, ref ident)| quote!(#this::#ident))
|
.map(|(_, ident)| quote!(#this::#ident))
|
||||||
.collect();
|
.collect();
|
||||||
let main_constructors: &Vec<_> = &fields
|
let main_constructors: &Vec<_> = &fields
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&(_, ref ident, _)| quote!(#this::#ident))
|
.map(|(_, ident, _)| quote!(#this::#ident))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let expecting = if is_variant {
|
let expecting = if is_variant {
|
||||||
@@ -2327,7 +2322,7 @@ fn deserialize_struct_as_struct_visitor(
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let fields_stmt = {
|
let fields_stmt = {
|
||||||
let field_names = field_names_idents.iter().map(|&(ref name, _, _)| name);
|
let field_names = field_names_idents.iter().map(|(name, _, _)| name);
|
||||||
quote_block! {
|
quote_block! {
|
||||||
const FIELDS: &'static [&'static str] = &[ #(#field_names),* ];
|
const FIELDS: &'static [&'static str] = &[ #(#field_names),* ];
|
||||||
}
|
}
|
||||||
@@ -2383,7 +2378,7 @@ fn deserialize_map(
|
|||||||
let let_values = fields_names
|
let let_values = fields_names
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|&&(field, _)| !field.attrs.skip_deserializing() && !field.attrs.flatten())
|
.filter(|&&(field, _)| !field.attrs.skip_deserializing() && !field.attrs.flatten())
|
||||||
.map(|&(field, ref name)| {
|
.map(|(field, name)| {
|
||||||
let field_ty = field.ty;
|
let field_ty = field.ty;
|
||||||
quote! {
|
quote! {
|
||||||
let mut #name: _serde::export::Option<#field_ty> = _serde::export::None;
|
let mut #name: _serde::export::Option<#field_ty> = _serde::export::None;
|
||||||
@@ -2406,7 +2401,7 @@ fn deserialize_map(
|
|||||||
let value_arms = fields_names
|
let value_arms = fields_names
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|&&(field, _)| !field.attrs.skip_deserializing() && !field.attrs.flatten())
|
.filter(|&&(field, _)| !field.attrs.skip_deserializing() && !field.attrs.flatten())
|
||||||
.map(|&(field, ref name)| {
|
.map(|(field, name)| {
|
||||||
let deser_name = field.attrs.name().deserialize_name();
|
let deser_name = field.attrs.name().deserialize_name();
|
||||||
|
|
||||||
let visit = match field.attrs.deserialize_with() {
|
let visit = match field.attrs.deserialize_with() {
|
||||||
@@ -2482,7 +2477,7 @@ fn deserialize_map(
|
|||||||
let extract_values = fields_names
|
let extract_values = fields_names
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|&&(field, _)| !field.attrs.skip_deserializing() && !field.attrs.flatten())
|
.filter(|&&(field, _)| !field.attrs.skip_deserializing() && !field.attrs.flatten())
|
||||||
.map(|&(field, ref name)| {
|
.map(|(field, name)| {
|
||||||
let missing_expr = Match(expr_is_missing(field, cattrs));
|
let missing_expr = Match(expr_is_missing(field, cattrs));
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
@@ -2496,7 +2491,7 @@ fn deserialize_map(
|
|||||||
let extract_collected = fields_names
|
let extract_collected = fields_names
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|&&(field, _)| field.attrs.flatten() && !field.attrs.skip_deserializing())
|
.filter(|&&(field, _)| field.attrs.flatten() && !field.attrs.skip_deserializing())
|
||||||
.map(|&(field, ref name)| {
|
.map(|(field, name)| {
|
||||||
let field_ty = field.ty;
|
let field_ty = field.ty;
|
||||||
let func = match field.attrs.deserialize_with() {
|
let func = match field.attrs.deserialize_with() {
|
||||||
None => {
|
None => {
|
||||||
@@ -2531,7 +2526,7 @@ fn deserialize_map(
|
|||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = fields_names.iter().map(|&(field, ref name)| {
|
let result = fields_names.iter().map(|(field, name)| {
|
||||||
let member = &field.member;
|
let member = &field.member;
|
||||||
if field.attrs.skip_deserializing() {
|
if field.attrs.skip_deserializing() {
|
||||||
let value = Expr(expr_is_missing(field, cattrs));
|
let value = Expr(expr_is_missing(field, cattrs));
|
||||||
@@ -2541,11 +2536,11 @@ fn deserialize_map(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let let_default = match *cattrs.default() {
|
let let_default = match cattrs.default() {
|
||||||
attr::Default::Default => Some(quote!(
|
attr::Default::Default => Some(quote!(
|
||||||
let __default: Self::Value = _serde::export::Default::default();
|
let __default: Self::Value = _serde::export::Default::default();
|
||||||
)),
|
)),
|
||||||
attr::Default::Path(ref path) => Some(quote!(
|
attr::Default::Path(path) => Some(quote!(
|
||||||
let __default: Self::Value = #path();
|
let __default: Self::Value = #path();
|
||||||
)),
|
)),
|
||||||
attr::Default::None => {
|
attr::Default::None => {
|
||||||
@@ -2604,7 +2599,7 @@ fn deserialize_struct_as_struct_in_place_visitor(
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let fields_stmt = {
|
let fields_stmt = {
|
||||||
let field_names = field_names_idents.iter().map(|&(ref name, _, _)| name);
|
let field_names = field_names_idents.iter().map(|(name, _, _)| name);
|
||||||
quote_block! {
|
quote_block! {
|
||||||
const FIELDS: &'static [&'static str] = &[ #(#field_names),* ];
|
const FIELDS: &'static [&'static str] = &[ #(#field_names),* ];
|
||||||
}
|
}
|
||||||
@@ -2637,7 +2632,7 @@ fn deserialize_map_in_place(
|
|||||||
let let_flags = fields_names
|
let let_flags = fields_names
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|&&(field, _)| !field.attrs.skip_deserializing())
|
.filter(|&&(field, _)| !field.attrs.skip_deserializing())
|
||||||
.map(|&(_, ref name)| {
|
.map(|(_, name)| {
|
||||||
quote! {
|
quote! {
|
||||||
let mut #name: bool = false;
|
let mut #name: bool = false;
|
||||||
}
|
}
|
||||||
@@ -2647,7 +2642,7 @@ fn deserialize_map_in_place(
|
|||||||
let value_arms_from = fields_names
|
let value_arms_from = fields_names
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|&&(field, _)| !field.attrs.skip_deserializing())
|
.filter(|&&(field, _)| !field.attrs.skip_deserializing())
|
||||||
.map(|&(field, ref name)| {
|
.map(|(field, name)| {
|
||||||
let deser_name = field.attrs.name().deserialize_name();
|
let deser_name = field.attrs.name().deserialize_name();
|
||||||
let member = &field.member;
|
let member = &field.member;
|
||||||
|
|
||||||
@@ -2714,7 +2709,7 @@ fn deserialize_map_in_place(
|
|||||||
let check_flags = fields_names
|
let check_flags = fields_names
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|&&(field, _)| !field.attrs.skip_deserializing())
|
.filter(|&&(field, _)| !field.attrs.skip_deserializing())
|
||||||
.map(|&(field, ref name)| {
|
.map(|(field, name)| {
|
||||||
let missing_expr = expr_is_missing(field, cattrs);
|
let missing_expr = expr_is_missing(field, cattrs);
|
||||||
// If missing_expr unconditionally returns an error, don't try
|
// If missing_expr unconditionally returns an error, don't try
|
||||||
// to assign its value to self.place.
|
// to assign its value to self.place.
|
||||||
@@ -2742,11 +2737,11 @@ fn deserialize_map_in_place(
|
|||||||
let this = ¶ms.this;
|
let this = ¶ms.this;
|
||||||
let (_, _, ty_generics, _) = split_with_de_lifetime(params);
|
let (_, _, ty_generics, _) = split_with_de_lifetime(params);
|
||||||
|
|
||||||
let let_default = match *cattrs.default() {
|
let let_default = match cattrs.default() {
|
||||||
attr::Default::Default => Some(quote!(
|
attr::Default::Default => Some(quote!(
|
||||||
let __default: #this #ty_generics = _serde::export::Default::default();
|
let __default: #this #ty_generics = _serde::export::Default::default();
|
||||||
)),
|
)),
|
||||||
attr::Default::Path(ref path) => Some(quote!(
|
attr::Default::Path(path) => Some(quote!(
|
||||||
let __default: #this #ty_generics = #path();
|
let __default: #this #ty_generics = #path();
|
||||||
)),
|
)),
|
||||||
attr::Default::None => {
|
attr::Default::None => {
|
||||||
@@ -2865,13 +2860,13 @@ fn wrap_deserialize_variant_with(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn expr_is_missing(field: &Field, cattrs: &attr::Container) -> Fragment {
|
fn expr_is_missing(field: &Field, cattrs: &attr::Container) -> Fragment {
|
||||||
match *field.attrs.default() {
|
match field.attrs.default() {
|
||||||
attr::Default::Default => {
|
attr::Default::Default => {
|
||||||
let span = field.original.span();
|
let span = field.original.span();
|
||||||
let func = quote_spanned!(span=> _serde::export::Default::default);
|
let func = quote_spanned!(span=> _serde::export::Default::default);
|
||||||
return quote_expr!(#func());
|
return quote_expr!(#func());
|
||||||
}
|
}
|
||||||
attr::Default::Path(ref path) => {
|
attr::Default::Path(path) => {
|
||||||
return quote_expr!(#path());
|
return quote_expr!(#path());
|
||||||
}
|
}
|
||||||
attr::Default::None => { /* below */ }
|
attr::Default::None => { /* below */ }
|
||||||
@@ -2935,11 +2930,11 @@ impl<'a> ToTokens for InPlaceImplGenerics<'a> {
|
|||||||
|
|
||||||
// Add lifetime for `&'place mut Self, and `'a: 'place`
|
// Add lifetime for `&'place mut Self, and `'a: 'place`
|
||||||
for param in &mut generics.params {
|
for param in &mut generics.params {
|
||||||
match *param {
|
match param {
|
||||||
syn::GenericParam::Lifetime(ref mut param) => {
|
syn::GenericParam::Lifetime(param) => {
|
||||||
param.bounds.push(place_lifetime.lifetime.clone());
|
param.bounds.push(place_lifetime.lifetime.clone());
|
||||||
}
|
}
|
||||||
syn::GenericParam::Type(ref mut param) => {
|
syn::GenericParam::Type(param) => {
|
||||||
param.bounds.push(syn::TypeParamBound::Lifetime(
|
param.bounds.push(syn::TypeParamBound::Lifetime(
|
||||||
place_lifetime.lifetime.clone(),
|
place_lifetime.lifetime.clone(),
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -27,9 +27,9 @@ macro_rules! quote_block {
|
|||||||
pub struct Expr(pub Fragment);
|
pub struct Expr(pub Fragment);
|
||||||
impl ToTokens for Expr {
|
impl ToTokens for Expr {
|
||||||
fn to_tokens(&self, out: &mut TokenStream) {
|
fn to_tokens(&self, out: &mut TokenStream) {
|
||||||
match self.0 {
|
match &self.0 {
|
||||||
Fragment::Expr(ref expr) => expr.to_tokens(out),
|
Fragment::Expr(expr) => expr.to_tokens(out),
|
||||||
Fragment::Block(ref block) => {
|
Fragment::Block(block) => {
|
||||||
token::Brace::default().surround(out, |out| block.to_tokens(out));
|
token::Brace::default().surround(out, |out| block.to_tokens(out));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -40,9 +40,9 @@ impl ToTokens for Expr {
|
|||||||
pub struct Stmts(pub Fragment);
|
pub struct Stmts(pub Fragment);
|
||||||
impl ToTokens for Stmts {
|
impl ToTokens for Stmts {
|
||||||
fn to_tokens(&self, out: &mut TokenStream) {
|
fn to_tokens(&self, out: &mut TokenStream) {
|
||||||
match self.0 {
|
match &self.0 {
|
||||||
Fragment::Expr(ref expr) => expr.to_tokens(out),
|
Fragment::Expr(expr) => expr.to_tokens(out),
|
||||||
Fragment::Block(ref block) => block.to_tokens(out),
|
Fragment::Block(block) => block.to_tokens(out),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -52,12 +52,12 @@ impl ToTokens for Stmts {
|
|||||||
pub struct Match(pub Fragment);
|
pub struct Match(pub Fragment);
|
||||||
impl ToTokens for Match {
|
impl ToTokens for Match {
|
||||||
fn to_tokens(&self, out: &mut TokenStream) {
|
fn to_tokens(&self, out: &mut TokenStream) {
|
||||||
match self.0 {
|
match &self.0 {
|
||||||
Fragment::Expr(ref expr) => {
|
Fragment::Expr(expr) => {
|
||||||
expr.to_tokens(out);
|
expr.to_tokens(out);
|
||||||
<Token![,]>::default().to_tokens(out);
|
<Token![,]>::default().to_tokens(out);
|
||||||
}
|
}
|
||||||
Fragment::Block(ref block) => {
|
Fragment::Block(block) => {
|
||||||
token::Brace::default().surround(out, |out| block.to_tokens(out));
|
token::Brace::default().surround(out, |out| block.to_tokens(out));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -66,9 +66,9 @@ impl ToTokens for Match {
|
|||||||
|
|
||||||
impl AsRef<TokenStream> for Fragment {
|
impl AsRef<TokenStream> for Fragment {
|
||||||
fn as_ref(&self) -> &TokenStream {
|
fn as_ref(&self) -> &TokenStream {
|
||||||
match *self {
|
match self {
|
||||||
Fragment::Expr(ref expr) => expr,
|
Fragment::Expr(expr) => expr,
|
||||||
Fragment::Block(ref block) => block,
|
Fragment::Block(block) => block,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,11 +67,9 @@ impl<'a> Container<'a> {
|
|||||||
) -> Option<Container<'a>> {
|
) -> Option<Container<'a>> {
|
||||||
let mut attrs = attr::Container::from_ast(cx, item);
|
let mut attrs = attr::Container::from_ast(cx, item);
|
||||||
|
|
||||||
let mut data = match item.data {
|
let mut data = match &item.data {
|
||||||
syn::Data::Enum(ref data) => {
|
syn::Data::Enum(data) => Data::Enum(enum_from_ast(cx, &data.variants, attrs.default())),
|
||||||
Data::Enum(enum_from_ast(cx, &data.variants, attrs.default()))
|
syn::Data::Struct(data) => {
|
||||||
}
|
|
||||||
syn::Data::Struct(ref data) => {
|
|
||||||
let (style, fields) = struct_from_ast(cx, &data.fields, None, attrs.default());
|
let (style, fields) = struct_from_ast(cx, &data.fields, None, attrs.default());
|
||||||
Data::Struct(style, fields)
|
Data::Struct(style, fields)
|
||||||
}
|
}
|
||||||
@@ -82,8 +80,8 @@ impl<'a> Container<'a> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let mut has_flatten = false;
|
let mut has_flatten = false;
|
||||||
match data {
|
match &mut data {
|
||||||
Data::Enum(ref mut variants) => {
|
Data::Enum(variants) => {
|
||||||
for variant in variants {
|
for variant in variants {
|
||||||
variant.attrs.rename_by_rules(attrs.rename_all_rules());
|
variant.attrs.rename_by_rules(attrs.rename_all_rules());
|
||||||
for field in &mut variant.fields {
|
for field in &mut variant.fields {
|
||||||
@@ -96,7 +94,7 @@ impl<'a> Container<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Data::Struct(_, ref mut fields) => {
|
Data::Struct(_, fields) => {
|
||||||
for field in fields {
|
for field in fields {
|
||||||
if field.attrs.flatten() {
|
if field.attrs.flatten() {
|
||||||
has_flatten = true;
|
has_flatten = true;
|
||||||
@@ -124,11 +122,11 @@ impl<'a> Container<'a> {
|
|||||||
|
|
||||||
impl<'a> Data<'a> {
|
impl<'a> Data<'a> {
|
||||||
pub fn all_fields(&'a self) -> Box<Iterator<Item = &'a Field<'a>> + 'a> {
|
pub fn all_fields(&'a self) -> Box<Iterator<Item = &'a Field<'a>> + 'a> {
|
||||||
match *self {
|
match self {
|
||||||
Data::Enum(ref variants) => {
|
Data::Enum(variants) => {
|
||||||
Box::new(variants.iter().flat_map(|variant| variant.fields.iter()))
|
Box::new(variants.iter().flat_map(|variant| variant.fields.iter()))
|
||||||
}
|
}
|
||||||
Data::Struct(_, ref fields) => Box::new(fields.iter()),
|
Data::Struct(_, fields) => Box::new(fields.iter()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,16 +163,16 @@ fn struct_from_ast<'a>(
|
|||||||
attrs: Option<&attr::Variant>,
|
attrs: Option<&attr::Variant>,
|
||||||
container_default: &attr::Default,
|
container_default: &attr::Default,
|
||||||
) -> (Style, Vec<Field<'a>>) {
|
) -> (Style, Vec<Field<'a>>) {
|
||||||
match *fields {
|
match fields {
|
||||||
syn::Fields::Named(ref fields) => (
|
syn::Fields::Named(fields) => (
|
||||||
Style::Struct,
|
Style::Struct,
|
||||||
fields_from_ast(cx, &fields.named, attrs, container_default),
|
fields_from_ast(cx, &fields.named, attrs, container_default),
|
||||||
),
|
),
|
||||||
syn::Fields::Unnamed(ref fields) if fields.unnamed.len() == 1 => (
|
syn::Fields::Unnamed(fields) if fields.unnamed.len() == 1 => (
|
||||||
Style::Newtype,
|
Style::Newtype,
|
||||||
fields_from_ast(cx, &fields.unnamed, attrs, container_default),
|
fields_from_ast(cx, &fields.unnamed, attrs, container_default),
|
||||||
),
|
),
|
||||||
syn::Fields::Unnamed(ref fields) => (
|
syn::Fields::Unnamed(fields) => (
|
||||||
Style::Tuple,
|
Style::Tuple,
|
||||||
fields_from_ast(cx, &fields.unnamed, attrs, container_default),
|
fields_from_ast(cx, &fields.unnamed, attrs, container_default),
|
||||||
),
|
),
|
||||||
@@ -192,8 +190,8 @@ fn fields_from_ast<'a>(
|
|||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, field)| Field {
|
.map(|(i, field)| Field {
|
||||||
member: match field.ident {
|
member: match &field.ident {
|
||||||
Some(ref ident) => syn::Member::Named(ident.clone()),
|
Some(ident) => syn::Member::Named(ident.clone()),
|
||||||
None => syn::Member::Unnamed(i.into()),
|
None => syn::Member::Unnamed(i.into()),
|
||||||
},
|
},
|
||||||
attrs: attr::Field::from_ast(cx, i, field, attrs, container_default),
|
attrs: attr::Field::from_ast(cx, i, field, attrs, container_default),
|
||||||
|
|||||||
+135
-173
@@ -311,9 +311,9 @@ impl Container {
|
|||||||
.flat_map(|attr| get_serde_meta_items(cx, attr))
|
.flat_map(|attr| get_serde_meta_items(cx, attr))
|
||||||
.flatten()
|
.flatten()
|
||||||
{
|
{
|
||||||
match meta_item {
|
match &meta_item {
|
||||||
// Parse `#[serde(rename = "foo")]`
|
// Parse `#[serde(rename = "foo")]`
|
||||||
Meta(NameValue(ref m)) if m.path == RENAME => {
|
Meta(NameValue(m)) if m.path == RENAME => {
|
||||||
if let Ok(s) = get_lit_str(cx, RENAME, &m.lit) {
|
if let Ok(s) = get_lit_str(cx, RENAME, &m.lit) {
|
||||||
ser_name.set(&m.path, s.value());
|
ser_name.set(&m.path, s.value());
|
||||||
de_name.set(&m.path, s.value());
|
de_name.set(&m.path, s.value());
|
||||||
@@ -321,7 +321,7 @@ impl Container {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(rename(serialize = "foo", deserialize = "bar"))]`
|
// Parse `#[serde(rename(serialize = "foo", deserialize = "bar"))]`
|
||||||
Meta(List(ref m)) if m.path == RENAME => {
|
Meta(List(m)) if m.path == RENAME => {
|
||||||
if let Ok((ser, de)) = get_renames(cx, &m.nested) {
|
if let Ok((ser, de)) = get_renames(cx, &m.nested) {
|
||||||
ser_name.set_opt(&m.path, ser.map(syn::LitStr::value));
|
ser_name.set_opt(&m.path, ser.map(syn::LitStr::value));
|
||||||
de_name.set_opt(&m.path, de.map(syn::LitStr::value));
|
de_name.set_opt(&m.path, de.map(syn::LitStr::value));
|
||||||
@@ -329,7 +329,7 @@ impl Container {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(rename_all = "foo")]`
|
// Parse `#[serde(rename_all = "foo")]`
|
||||||
Meta(NameValue(ref m)) if m.path == RENAME_ALL => {
|
Meta(NameValue(m)) if m.path == RENAME_ALL => {
|
||||||
if let Ok(s) = get_lit_str(cx, RENAME_ALL, &m.lit) {
|
if let Ok(s) = get_lit_str(cx, RENAME_ALL, &m.lit) {
|
||||||
match RenameRule::from_str(&s.value()) {
|
match RenameRule::from_str(&s.value()) {
|
||||||
Ok(rename_rule) => {
|
Ok(rename_rule) => {
|
||||||
@@ -348,7 +348,7 @@ impl Container {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(rename_all(serialize = "foo", deserialize = "bar"))]`
|
// Parse `#[serde(rename_all(serialize = "foo", deserialize = "bar"))]`
|
||||||
Meta(List(ref m)) if m.path == RENAME_ALL => {
|
Meta(List(m)) if m.path == RENAME_ALL => {
|
||||||
if let Ok((ser, de)) = get_renames(cx, &m.nested) {
|
if let Ok((ser, de)) = get_renames(cx, &m.nested) {
|
||||||
if let Some(ser) = ser {
|
if let Some(ser) = ser {
|
||||||
match RenameRule::from_str(&ser.value()) {
|
match RenameRule::from_str(&ser.value()) {
|
||||||
@@ -378,18 +378,18 @@ impl Container {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(transparent)]`
|
// Parse `#[serde(transparent)]`
|
||||||
Meta(Path(ref word)) if word == TRANSPARENT => {
|
Meta(Path(word)) if word == TRANSPARENT => {
|
||||||
transparent.set_true(word);
|
transparent.set_true(word);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(deny_unknown_fields)]`
|
// Parse `#[serde(deny_unknown_fields)]`
|
||||||
Meta(Path(ref word)) if word == DENY_UNKNOWN_FIELDS => {
|
Meta(Path(word)) if word == DENY_UNKNOWN_FIELDS => {
|
||||||
deny_unknown_fields.set_true(word);
|
deny_unknown_fields.set_true(word);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(default)]`
|
// Parse `#[serde(default)]`
|
||||||
Meta(Path(ref word)) if word == DEFAULT => match item.data {
|
Meta(Path(word)) if word == DEFAULT => match &item.data {
|
||||||
syn::Data::Struct(syn::DataStruct { ref fields, .. }) => match *fields {
|
syn::Data::Struct(syn::DataStruct { fields, .. }) => match fields {
|
||||||
syn::Fields::Named(_) => {
|
syn::Fields::Named(_) => {
|
||||||
default.set(word, Default::Default);
|
default.set(word, Default::Default);
|
||||||
}
|
}
|
||||||
@@ -398,24 +398,22 @@ impl Container {
|
|||||||
"#[serde(default)] can only be used on structs with named fields",
|
"#[serde(default)] can only be used on structs with named fields",
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
syn::Data::Enum(syn::DataEnum { ref enum_token, .. }) => cx.error_spanned_by(
|
syn::Data::Enum(syn::DataEnum { enum_token, .. }) => cx.error_spanned_by(
|
||||||
enum_token,
|
enum_token,
|
||||||
"#[serde(default)] can only be used on structs with named fields",
|
"#[serde(default)] can only be used on structs with named fields",
|
||||||
),
|
),
|
||||||
syn::Data::Union(syn::DataUnion {
|
syn::Data::Union(syn::DataUnion { union_token, .. }) => cx.error_spanned_by(
|
||||||
ref union_token, ..
|
|
||||||
}) => cx.error_spanned_by(
|
|
||||||
union_token,
|
union_token,
|
||||||
"#[serde(default)] can only be used on structs with named fields",
|
"#[serde(default)] can only be used on structs with named fields",
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|
||||||
// Parse `#[serde(default = "...")]`
|
// Parse `#[serde(default = "...")]`
|
||||||
Meta(NameValue(ref m)) if m.path == DEFAULT => {
|
Meta(NameValue(m)) if m.path == DEFAULT => {
|
||||||
if let Ok(path) = parse_lit_into_expr_path(cx, DEFAULT, &m.lit) {
|
if let Ok(path) = parse_lit_into_expr_path(cx, DEFAULT, &m.lit) {
|
||||||
match item.data {
|
match &item.data {
|
||||||
syn::Data::Struct(syn::DataStruct { ref fields, .. }) => {
|
syn::Data::Struct(syn::DataStruct { fields, .. }) => {
|
||||||
match *fields {
|
match fields {
|
||||||
syn::Fields::Named(_) => {
|
syn::Fields::Named(_) => {
|
||||||
default.set(&m.path, Default::Path(path));
|
default.set(&m.path, Default::Path(path));
|
||||||
}
|
}
|
||||||
@@ -426,13 +424,13 @@ impl Container {
|
|||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
syn::Data::Enum(syn::DataEnum { ref enum_token, .. }) => cx
|
syn::Data::Enum(syn::DataEnum { enum_token, .. }) => cx
|
||||||
.error_spanned_by(
|
.error_spanned_by(
|
||||||
enum_token,
|
enum_token,
|
||||||
"#[serde(default = \"...\")] can only be used on structs with named fields",
|
"#[serde(default = \"...\")] can only be used on structs with named fields",
|
||||||
),
|
),
|
||||||
syn::Data::Union(syn::DataUnion {
|
syn::Data::Union(syn::DataUnion {
|
||||||
ref union_token, ..
|
union_token, ..
|
||||||
}) => cx.error_spanned_by(
|
}) => cx.error_spanned_by(
|
||||||
union_token,
|
union_token,
|
||||||
"#[serde(default = \"...\")] can only be used on structs with named fields",
|
"#[serde(default = \"...\")] can only be used on structs with named fields",
|
||||||
@@ -442,7 +440,7 @@ impl Container {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(bound = "T: SomeBound")]`
|
// Parse `#[serde(bound = "T: SomeBound")]`
|
||||||
Meta(NameValue(ref m)) if m.path == BOUND => {
|
Meta(NameValue(m)) if m.path == BOUND => {
|
||||||
if let Ok(where_predicates) = parse_lit_into_where(cx, BOUND, BOUND, &m.lit) {
|
if let Ok(where_predicates) = parse_lit_into_where(cx, BOUND, BOUND, &m.lit) {
|
||||||
ser_bound.set(&m.path, where_predicates.clone());
|
ser_bound.set(&m.path, where_predicates.clone());
|
||||||
de_bound.set(&m.path, where_predicates);
|
de_bound.set(&m.path, where_predicates);
|
||||||
@@ -450,7 +448,7 @@ impl Container {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(bound(serialize = "...", deserialize = "..."))]`
|
// Parse `#[serde(bound(serialize = "...", deserialize = "..."))]`
|
||||||
Meta(List(ref m)) if m.path == BOUND => {
|
Meta(List(m)) if m.path == BOUND => {
|
||||||
if let Ok((ser, de)) = get_where_predicates(cx, &m.nested) {
|
if let Ok((ser, de)) = get_where_predicates(cx, &m.nested) {
|
||||||
ser_bound.set_opt(&m.path, ser);
|
ser_bound.set_opt(&m.path, ser);
|
||||||
de_bound.set_opt(&m.path, de);
|
de_bound.set_opt(&m.path, de);
|
||||||
@@ -458,21 +456,17 @@ impl Container {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(untagged)]`
|
// Parse `#[serde(untagged)]`
|
||||||
Meta(Path(ref word)) if word == UNTAGGED => match item.data {
|
Meta(Path(word)) if word == UNTAGGED => match item.data {
|
||||||
syn::Data::Enum(_) => {
|
syn::Data::Enum(_) => {
|
||||||
untagged.set_true(word);
|
untagged.set_true(word);
|
||||||
}
|
}
|
||||||
syn::Data::Struct(syn::DataStruct {
|
syn::Data::Struct(syn::DataStruct { struct_token, .. }) => {
|
||||||
ref struct_token, ..
|
|
||||||
}) => {
|
|
||||||
cx.error_spanned_by(
|
cx.error_spanned_by(
|
||||||
struct_token,
|
struct_token,
|
||||||
"#[serde(untagged)] can only be used on enums",
|
"#[serde(untagged)] can only be used on enums",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
syn::Data::Union(syn::DataUnion {
|
syn::Data::Union(syn::DataUnion { union_token, .. }) => {
|
||||||
ref union_token, ..
|
|
||||||
}) => {
|
|
||||||
cx.error_spanned_by(
|
cx.error_spanned_by(
|
||||||
union_token,
|
union_token,
|
||||||
"#[serde(untagged)] can only be used on enums",
|
"#[serde(untagged)] can only be used on enums",
|
||||||
@@ -481,28 +475,24 @@ impl Container {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Parse `#[serde(tag = "type")]`
|
// Parse `#[serde(tag = "type")]`
|
||||||
Meta(NameValue(ref m)) if m.path == TAG => {
|
Meta(NameValue(m)) if m.path == TAG => {
|
||||||
if let Ok(s) = get_lit_str(cx, TAG, &m.lit) {
|
if let Ok(s) = get_lit_str(cx, TAG, &m.lit) {
|
||||||
match item.data {
|
match &item.data {
|
||||||
syn::Data::Enum(_) => {
|
syn::Data::Enum(_) => {
|
||||||
internal_tag.set(&m.path, s.value());
|
internal_tag.set(&m.path, s.value());
|
||||||
}
|
}
|
||||||
syn::Data::Struct(syn::DataStruct { ref fields, .. }) => {
|
syn::Data::Struct(syn::DataStruct { fields, .. }) => match fields {
|
||||||
match *fields {
|
syn::Fields::Named(_) => {
|
||||||
syn::Fields::Named(_) => {
|
internal_tag.set(&m.path, s.value());
|
||||||
internal_tag.set(&m.path, s.value());
|
}
|
||||||
}
|
syn::Fields::Unnamed(_) | syn::Fields::Unit => {
|
||||||
syn::Fields::Unnamed(_) | syn::Fields::Unit => {
|
cx.error_spanned_by(
|
||||||
cx.error_spanned_by(
|
|
||||||
fields,
|
fields,
|
||||||
"#[serde(tag = \"...\")] can only be used on enums and structs with named fields",
|
"#[serde(tag = \"...\")] can only be used on enums and structs with named fields",
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
syn::Data::Union(syn::DataUnion {
|
syn::Data::Union(syn::DataUnion { union_token, .. }) => {
|
||||||
ref union_token, ..
|
|
||||||
}) => {
|
|
||||||
cx.error_spanned_by(
|
cx.error_spanned_by(
|
||||||
union_token,
|
union_token,
|
||||||
"#[serde(tag = \"...\")] can only be used on enums and structs with named fields",
|
"#[serde(tag = \"...\")] can only be used on enums and structs with named fields",
|
||||||
@@ -513,23 +503,19 @@ impl Container {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(content = "c")]`
|
// Parse `#[serde(content = "c")]`
|
||||||
Meta(NameValue(ref m)) if m.path == CONTENT => {
|
Meta(NameValue(m)) if m.path == CONTENT => {
|
||||||
if let Ok(s) = get_lit_str(cx, CONTENT, &m.lit) {
|
if let Ok(s) = get_lit_str(cx, CONTENT, &m.lit) {
|
||||||
match item.data {
|
match &item.data {
|
||||||
syn::Data::Enum(_) => {
|
syn::Data::Enum(_) => {
|
||||||
content.set(&m.path, s.value());
|
content.set(&m.path, s.value());
|
||||||
}
|
}
|
||||||
syn::Data::Struct(syn::DataStruct {
|
syn::Data::Struct(syn::DataStruct { struct_token, .. }) => {
|
||||||
ref struct_token, ..
|
|
||||||
}) => {
|
|
||||||
cx.error_spanned_by(
|
cx.error_spanned_by(
|
||||||
struct_token,
|
struct_token,
|
||||||
"#[serde(content = \"...\")] can only be used on enums",
|
"#[serde(content = \"...\")] can only be used on enums",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
syn::Data::Union(syn::DataUnion {
|
syn::Data::Union(syn::DataUnion { union_token, .. }) => {
|
||||||
ref union_token, ..
|
|
||||||
}) => {
|
|
||||||
cx.error_spanned_by(
|
cx.error_spanned_by(
|
||||||
union_token,
|
union_token,
|
||||||
"#[serde(content = \"...\")] can only be used on enums",
|
"#[serde(content = \"...\")] can only be used on enums",
|
||||||
@@ -540,28 +526,28 @@ impl Container {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(from = "Type")]
|
// Parse `#[serde(from = "Type")]
|
||||||
Meta(NameValue(ref m)) if m.path == FROM => {
|
Meta(NameValue(m)) if m.path == FROM => {
|
||||||
if let Ok(from_ty) = parse_lit_into_ty(cx, FROM, &m.lit) {
|
if let Ok(from_ty) = parse_lit_into_ty(cx, FROM, &m.lit) {
|
||||||
type_from.set_opt(&m.path, Some(from_ty));
|
type_from.set_opt(&m.path, Some(from_ty));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(try_from = "Type")]
|
// Parse `#[serde(try_from = "Type")]
|
||||||
Meta(NameValue(ref m)) if m.path == TRY_FROM => {
|
Meta(NameValue(m)) if m.path == TRY_FROM => {
|
||||||
if let Ok(try_from_ty) = parse_lit_into_ty(cx, TRY_FROM, &m.lit) {
|
if let Ok(try_from_ty) = parse_lit_into_ty(cx, TRY_FROM, &m.lit) {
|
||||||
type_try_from.set_opt(&m.path, Some(try_from_ty));
|
type_try_from.set_opt(&m.path, Some(try_from_ty));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(into = "Type")]
|
// Parse `#[serde(into = "Type")]
|
||||||
Meta(NameValue(ref m)) if m.path == INTO => {
|
Meta(NameValue(m)) if m.path == INTO => {
|
||||||
if let Ok(into_ty) = parse_lit_into_ty(cx, INTO, &m.lit) {
|
if let Ok(into_ty) = parse_lit_into_ty(cx, INTO, &m.lit) {
|
||||||
type_into.set_opt(&m.path, Some(into_ty));
|
type_into.set_opt(&m.path, Some(into_ty));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(remote = "...")]`
|
// Parse `#[serde(remote = "...")]`
|
||||||
Meta(NameValue(ref m)) if m.path == REMOTE => {
|
Meta(NameValue(m)) if m.path == REMOTE => {
|
||||||
if let Ok(path) = parse_lit_into_path(cx, REMOTE, &m.lit) {
|
if let Ok(path) = parse_lit_into_path(cx, REMOTE, &m.lit) {
|
||||||
if is_primitive_path(&path, "Self") {
|
if is_primitive_path(&path, "Self") {
|
||||||
remote.set(&m.path, item.ident.clone().into());
|
remote.set(&m.path, item.ident.clone().into());
|
||||||
@@ -572,23 +558,23 @@ impl Container {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(field_identifier)]`
|
// Parse `#[serde(field_identifier)]`
|
||||||
Meta(Path(ref word)) if word == FIELD_IDENTIFIER => {
|
Meta(Path(word)) if word == FIELD_IDENTIFIER => {
|
||||||
field_identifier.set_true(word);
|
field_identifier.set_true(word);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(variant_identifier)]`
|
// Parse `#[serde(variant_identifier)]`
|
||||||
Meta(Path(ref word)) if word == VARIANT_IDENTIFIER => {
|
Meta(Path(word)) if word == VARIANT_IDENTIFIER => {
|
||||||
variant_identifier.set_true(word);
|
variant_identifier.set_true(word);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(crate = "foo")]`
|
// Parse `#[serde(crate = "foo")]`
|
||||||
Meta(NameValue(ref m)) if m.path == CRATE => {
|
Meta(NameValue(m)) if m.path == CRATE => {
|
||||||
if let Ok(path) = parse_lit_into_path(cx, CRATE, &m.lit) {
|
if let Ok(path) = parse_lit_into_path(cx, CRATE, &m.lit) {
|
||||||
serde_path.set(&m.path, path)
|
serde_path.set(&m.path, path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Meta(ref meta_item) => {
|
Meta(meta_item) => {
|
||||||
let path = meta_item
|
let path = meta_item
|
||||||
.path()
|
.path()
|
||||||
.into_token_stream()
|
.into_token_stream()
|
||||||
@@ -600,7 +586,7 @@ impl Container {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Lit(ref lit) => {
|
Lit(lit) => {
|
||||||
cx.error_spanned_by(lit, "unexpected literal in serde container attribute");
|
cx.error_spanned_by(lit, "unexpected literal in serde container attribute");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -714,11 +700,11 @@ fn decide_tag(
|
|||||||
(Some(_), None, None) => TagType::None,
|
(Some(_), None, None) => TagType::None,
|
||||||
(None, Some((_, tag)), None) => {
|
(None, Some((_, tag)), None) => {
|
||||||
// Check that there are no tuple variants.
|
// Check that there are no tuple variants.
|
||||||
if let syn::Data::Enum(ref data) = item.data {
|
if let syn::Data::Enum(data) = &item.data {
|
||||||
for variant in &data.variants {
|
for variant in &data.variants {
|
||||||
match variant.fields {
|
match &variant.fields {
|
||||||
syn::Fields::Named(_) | syn::Fields::Unit => {}
|
syn::Fields::Named(_) | syn::Fields::Unit => {}
|
||||||
syn::Fields::Unnamed(ref fields) => {
|
syn::Fields::Unnamed(fields) => {
|
||||||
if fields.unnamed.len() != 1 {
|
if fields.unnamed.len() != 1 {
|
||||||
cx.error_spanned_by(
|
cx.error_spanned_by(
|
||||||
variant,
|
variant,
|
||||||
@@ -806,54 +792,30 @@ fn decide_identifier(
|
|||||||
);
|
);
|
||||||
Identifier::No
|
Identifier::No
|
||||||
}
|
}
|
||||||
(&syn::Data::Enum(_), Some(_), None) => Identifier::Field,
|
(syn::Data::Enum(_), Some(_), None) => Identifier::Field,
|
||||||
(&syn::Data::Enum(_), None, Some(_)) => Identifier::Variant,
|
(syn::Data::Enum(_), None, Some(_)) => Identifier::Variant,
|
||||||
(
|
(syn::Data::Struct(syn::DataStruct { struct_token, .. }), Some(_), None) => {
|
||||||
&syn::Data::Struct(syn::DataStruct {
|
|
||||||
ref struct_token, ..
|
|
||||||
}),
|
|
||||||
Some(_),
|
|
||||||
None,
|
|
||||||
) => {
|
|
||||||
cx.error_spanned_by(
|
cx.error_spanned_by(
|
||||||
struct_token,
|
struct_token,
|
||||||
"#[serde(field_identifier)] can only be used on an enum",
|
"#[serde(field_identifier)] can only be used on an enum",
|
||||||
);
|
);
|
||||||
Identifier::No
|
Identifier::No
|
||||||
}
|
}
|
||||||
(
|
(syn::Data::Union(syn::DataUnion { union_token, .. }), Some(_), None) => {
|
||||||
&syn::Data::Union(syn::DataUnion {
|
|
||||||
ref union_token, ..
|
|
||||||
}),
|
|
||||||
Some(_),
|
|
||||||
None,
|
|
||||||
) => {
|
|
||||||
cx.error_spanned_by(
|
cx.error_spanned_by(
|
||||||
union_token,
|
union_token,
|
||||||
"#[serde(field_identifier)] can only be used on an enum",
|
"#[serde(field_identifier)] can only be used on an enum",
|
||||||
);
|
);
|
||||||
Identifier::No
|
Identifier::No
|
||||||
}
|
}
|
||||||
(
|
(syn::Data::Struct(syn::DataStruct { struct_token, .. }), None, Some(_)) => {
|
||||||
&syn::Data::Struct(syn::DataStruct {
|
|
||||||
ref struct_token, ..
|
|
||||||
}),
|
|
||||||
None,
|
|
||||||
Some(_),
|
|
||||||
) => {
|
|
||||||
cx.error_spanned_by(
|
cx.error_spanned_by(
|
||||||
struct_token,
|
struct_token,
|
||||||
"#[serde(variant_identifier)] can only be used on an enum",
|
"#[serde(variant_identifier)] can only be used on an enum",
|
||||||
);
|
);
|
||||||
Identifier::No
|
Identifier::No
|
||||||
}
|
}
|
||||||
(
|
(syn::Data::Union(syn::DataUnion { union_token, .. }), None, Some(_)) => {
|
||||||
&syn::Data::Union(syn::DataUnion {
|
|
||||||
ref union_token, ..
|
|
||||||
}),
|
|
||||||
None,
|
|
||||||
Some(_),
|
|
||||||
) => {
|
|
||||||
cx.error_spanned_by(
|
cx.error_spanned_by(
|
||||||
union_token,
|
union_token,
|
||||||
"#[serde(variant_identifier)] can only be used on an enum",
|
"#[serde(variant_identifier)] can only be used on an enum",
|
||||||
@@ -899,9 +861,9 @@ impl Variant {
|
|||||||
.flat_map(|attr| get_serde_meta_items(cx, attr))
|
.flat_map(|attr| get_serde_meta_items(cx, attr))
|
||||||
.flatten()
|
.flatten()
|
||||||
{
|
{
|
||||||
match meta_item {
|
match &meta_item {
|
||||||
// Parse `#[serde(rename = "foo")]`
|
// Parse `#[serde(rename = "foo")]`
|
||||||
Meta(NameValue(ref m)) if m.path == RENAME => {
|
Meta(NameValue(m)) if m.path == RENAME => {
|
||||||
if let Ok(s) = get_lit_str(cx, RENAME, &m.lit) {
|
if let Ok(s) = get_lit_str(cx, RENAME, &m.lit) {
|
||||||
ser_name.set(&m.path, s.value());
|
ser_name.set(&m.path, s.value());
|
||||||
de_name.set_if_none(s.value());
|
de_name.set_if_none(s.value());
|
||||||
@@ -910,7 +872,7 @@ impl Variant {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(rename(serialize = "foo", deserialize = "bar"))]`
|
// Parse `#[serde(rename(serialize = "foo", deserialize = "bar"))]`
|
||||||
Meta(List(ref m)) if m.path == RENAME => {
|
Meta(List(m)) if m.path == RENAME => {
|
||||||
if let Ok((ser, de)) = get_multiple_renames(cx, &m.nested) {
|
if let Ok((ser, de)) = get_multiple_renames(cx, &m.nested) {
|
||||||
ser_name.set_opt(&m.path, ser.map(syn::LitStr::value));
|
ser_name.set_opt(&m.path, ser.map(syn::LitStr::value));
|
||||||
for de_value in de {
|
for de_value in de {
|
||||||
@@ -921,14 +883,14 @@ impl Variant {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(alias = "foo")]`
|
// Parse `#[serde(alias = "foo")]`
|
||||||
Meta(NameValue(ref m)) if m.path == ALIAS => {
|
Meta(NameValue(m)) if m.path == ALIAS => {
|
||||||
if let Ok(s) = get_lit_str(cx, ALIAS, &m.lit) {
|
if let Ok(s) = get_lit_str(cx, ALIAS, &m.lit) {
|
||||||
de_aliases.insert(&m.path, s.value());
|
de_aliases.insert(&m.path, s.value());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(rename_all = "foo")]`
|
// Parse `#[serde(rename_all = "foo")]`
|
||||||
Meta(NameValue(ref m)) if m.path == RENAME_ALL => {
|
Meta(NameValue(m)) if m.path == RENAME_ALL => {
|
||||||
if let Ok(s) = get_lit_str(cx, RENAME_ALL, &m.lit) {
|
if let Ok(s) = get_lit_str(cx, RENAME_ALL, &m.lit) {
|
||||||
match RenameRule::from_str(&s.value()) {
|
match RenameRule::from_str(&s.value()) {
|
||||||
Ok(rename_rule) => {
|
Ok(rename_rule) => {
|
||||||
@@ -947,7 +909,7 @@ impl Variant {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(rename_all(serialize = "foo", deserialize = "bar"))]`
|
// Parse `#[serde(rename_all(serialize = "foo", deserialize = "bar"))]`
|
||||||
Meta(List(ref m)) if m.path == RENAME_ALL => {
|
Meta(List(m)) if m.path == RENAME_ALL => {
|
||||||
if let Ok((ser, de)) = get_renames(cx, &m.nested) {
|
if let Ok((ser, de)) = get_renames(cx, &m.nested) {
|
||||||
if let Some(ser) = ser {
|
if let Some(ser) = ser {
|
||||||
match RenameRule::from_str(&ser.value()) {
|
match RenameRule::from_str(&ser.value()) {
|
||||||
@@ -977,28 +939,28 @@ impl Variant {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(skip)]`
|
// Parse `#[serde(skip)]`
|
||||||
Meta(Path(ref word)) if word == SKIP => {
|
Meta(Path(word)) if word == SKIP => {
|
||||||
skip_serializing.set_true(word);
|
skip_serializing.set_true(word);
|
||||||
skip_deserializing.set_true(word);
|
skip_deserializing.set_true(word);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(skip_deserializing)]`
|
// Parse `#[serde(skip_deserializing)]`
|
||||||
Meta(Path(ref word)) if word == SKIP_DESERIALIZING => {
|
Meta(Path(word)) if word == SKIP_DESERIALIZING => {
|
||||||
skip_deserializing.set_true(word);
|
skip_deserializing.set_true(word);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(skip_serializing)]`
|
// Parse `#[serde(skip_serializing)]`
|
||||||
Meta(Path(ref word)) if word == SKIP_SERIALIZING => {
|
Meta(Path(word)) if word == SKIP_SERIALIZING => {
|
||||||
skip_serializing.set_true(word);
|
skip_serializing.set_true(word);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(other)]`
|
// Parse `#[serde(other)]`
|
||||||
Meta(Path(ref word)) if word == OTHER => {
|
Meta(Path(word)) if word == OTHER => {
|
||||||
other.set_true(word);
|
other.set_true(word);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(bound = "T: SomeBound")]`
|
// Parse `#[serde(bound = "T: SomeBound")]`
|
||||||
Meta(NameValue(ref m)) if m.path == BOUND => {
|
Meta(NameValue(m)) if m.path == BOUND => {
|
||||||
if let Ok(where_predicates) = parse_lit_into_where(cx, BOUND, BOUND, &m.lit) {
|
if let Ok(where_predicates) = parse_lit_into_where(cx, BOUND, BOUND, &m.lit) {
|
||||||
ser_bound.set(&m.path, where_predicates.clone());
|
ser_bound.set(&m.path, where_predicates.clone());
|
||||||
de_bound.set(&m.path, where_predicates);
|
de_bound.set(&m.path, where_predicates);
|
||||||
@@ -1006,7 +968,7 @@ impl Variant {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(bound(serialize = "...", deserialize = "..."))]`
|
// Parse `#[serde(bound(serialize = "...", deserialize = "..."))]`
|
||||||
Meta(List(ref m)) if m.path == BOUND => {
|
Meta(List(m)) if m.path == BOUND => {
|
||||||
if let Ok((ser, de)) = get_where_predicates(cx, &m.nested) {
|
if let Ok((ser, de)) = get_where_predicates(cx, &m.nested) {
|
||||||
ser_bound.set_opt(&m.path, ser);
|
ser_bound.set_opt(&m.path, ser);
|
||||||
de_bound.set_opt(&m.path, de);
|
de_bound.set_opt(&m.path, de);
|
||||||
@@ -1014,7 +976,7 @@ impl Variant {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(with = "...")]`
|
// Parse `#[serde(with = "...")]`
|
||||||
Meta(NameValue(ref m)) if m.path == WITH => {
|
Meta(NameValue(m)) if m.path == WITH => {
|
||||||
if let Ok(path) = parse_lit_into_expr_path(cx, WITH, &m.lit) {
|
if let Ok(path) = parse_lit_into_expr_path(cx, WITH, &m.lit) {
|
||||||
let mut ser_path = path.clone();
|
let mut ser_path = path.clone();
|
||||||
ser_path
|
ser_path
|
||||||
@@ -1032,22 +994,22 @@ impl Variant {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(serialize_with = "...")]`
|
// Parse `#[serde(serialize_with = "...")]`
|
||||||
Meta(NameValue(ref m)) if m.path == SERIALIZE_WITH => {
|
Meta(NameValue(m)) if m.path == SERIALIZE_WITH => {
|
||||||
if let Ok(path) = parse_lit_into_expr_path(cx, SERIALIZE_WITH, &m.lit) {
|
if let Ok(path) = parse_lit_into_expr_path(cx, SERIALIZE_WITH, &m.lit) {
|
||||||
serialize_with.set(&m.path, path);
|
serialize_with.set(&m.path, path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(deserialize_with = "...")]`
|
// Parse `#[serde(deserialize_with = "...")]`
|
||||||
Meta(NameValue(ref m)) if m.path == DESERIALIZE_WITH => {
|
Meta(NameValue(m)) if m.path == DESERIALIZE_WITH => {
|
||||||
if let Ok(path) = parse_lit_into_expr_path(cx, DESERIALIZE_WITH, &m.lit) {
|
if let Ok(path) = parse_lit_into_expr_path(cx, DESERIALIZE_WITH, &m.lit) {
|
||||||
deserialize_with.set(&m.path, path);
|
deserialize_with.set(&m.path, path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Defer `#[serde(borrow)]` and `#[serde(borrow = "'a + 'b")]`
|
// Defer `#[serde(borrow)]` and `#[serde(borrow = "'a + 'b")]`
|
||||||
Meta(ref m) if m.path() == BORROW => match variant.fields {
|
Meta(m) if m.path() == BORROW => match &variant.fields {
|
||||||
syn::Fields::Unnamed(ref fields) if fields.unnamed.len() == 1 => {
|
syn::Fields::Unnamed(fields) if fields.unnamed.len() == 1 => {
|
||||||
borrow.set(m.path(), m.clone());
|
borrow.set(m.path(), m.clone());
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
@@ -1058,7 +1020,7 @@ impl Variant {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
Meta(ref meta_item) => {
|
Meta(meta_item) => {
|
||||||
let path = meta_item
|
let path = meta_item
|
||||||
.path()
|
.path()
|
||||||
.into_token_stream()
|
.into_token_stream()
|
||||||
@@ -1070,7 +1032,7 @@ impl Variant {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Lit(ref lit) => {
|
Lit(lit) => {
|
||||||
cx.error_spanned_by(lit, "unexpected literal in serde variant attribute");
|
cx.error_spanned_by(lit, "unexpected literal in serde variant attribute");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1172,7 +1134,7 @@ pub enum Default {
|
|||||||
|
|
||||||
impl Default {
|
impl Default {
|
||||||
pub fn is_none(&self) -> bool {
|
pub fn is_none(&self) -> bool {
|
||||||
match *self {
|
match self {
|
||||||
Default::None => true,
|
Default::None => true,
|
||||||
Default::Default | Default::Path(_) => false,
|
Default::Default | Default::Path(_) => false,
|
||||||
}
|
}
|
||||||
@@ -1203,8 +1165,8 @@ impl Field {
|
|||||||
let mut getter = Attr::none(cx, GETTER);
|
let mut getter = Attr::none(cx, GETTER);
|
||||||
let mut flatten = BoolAttr::none(cx, FLATTEN);
|
let mut flatten = BoolAttr::none(cx, FLATTEN);
|
||||||
|
|
||||||
let ident = match field.ident {
|
let ident = match &field.ident {
|
||||||
Some(ref ident) => unraw(ident),
|
Some(ident) => unraw(ident),
|
||||||
None => index.to_string(),
|
None => index.to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1219,9 +1181,9 @@ impl Field {
|
|||||||
.flatten()
|
.flatten()
|
||||||
.chain(variant_borrow)
|
.chain(variant_borrow)
|
||||||
{
|
{
|
||||||
match meta_item {
|
match &meta_item {
|
||||||
// Parse `#[serde(rename = "foo")]`
|
// Parse `#[serde(rename = "foo")]`
|
||||||
Meta(NameValue(ref m)) if m.path == RENAME => {
|
Meta(NameValue(m)) if m.path == RENAME => {
|
||||||
if let Ok(s) = get_lit_str(cx, RENAME, &m.lit) {
|
if let Ok(s) = get_lit_str(cx, RENAME, &m.lit) {
|
||||||
ser_name.set(&m.path, s.value());
|
ser_name.set(&m.path, s.value());
|
||||||
de_name.set_if_none(s.value());
|
de_name.set_if_none(s.value());
|
||||||
@@ -1230,7 +1192,7 @@ impl Field {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(rename(serialize = "foo", deserialize = "bar"))]`
|
// Parse `#[serde(rename(serialize = "foo", deserialize = "bar"))]`
|
||||||
Meta(List(ref m)) if m.path == RENAME => {
|
Meta(List(m)) if m.path == RENAME => {
|
||||||
if let Ok((ser, de)) = get_multiple_renames(cx, &m.nested) {
|
if let Ok((ser, de)) = get_multiple_renames(cx, &m.nested) {
|
||||||
ser_name.set_opt(&m.path, ser.map(syn::LitStr::value));
|
ser_name.set_opt(&m.path, ser.map(syn::LitStr::value));
|
||||||
for de_value in de {
|
for de_value in de {
|
||||||
@@ -1241,63 +1203,63 @@ impl Field {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(alias = "foo")]`
|
// Parse `#[serde(alias = "foo")]`
|
||||||
Meta(NameValue(ref m)) if m.path == ALIAS => {
|
Meta(NameValue(m)) if m.path == ALIAS => {
|
||||||
if let Ok(s) = get_lit_str(cx, ALIAS, &m.lit) {
|
if let Ok(s) = get_lit_str(cx, ALIAS, &m.lit) {
|
||||||
de_aliases.insert(&m.path, s.value());
|
de_aliases.insert(&m.path, s.value());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(default)]`
|
// Parse `#[serde(default)]`
|
||||||
Meta(Path(ref word)) if word == DEFAULT => {
|
Meta(Path(word)) if word == DEFAULT => {
|
||||||
default.set(word, Default::Default);
|
default.set(word, Default::Default);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(default = "...")]`
|
// Parse `#[serde(default = "...")]`
|
||||||
Meta(NameValue(ref m)) if m.path == DEFAULT => {
|
Meta(NameValue(m)) if m.path == DEFAULT => {
|
||||||
if let Ok(path) = parse_lit_into_expr_path(cx, DEFAULT, &m.lit) {
|
if let Ok(path) = parse_lit_into_expr_path(cx, DEFAULT, &m.lit) {
|
||||||
default.set(&m.path, Default::Path(path));
|
default.set(&m.path, Default::Path(path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(skip_serializing)]`
|
// Parse `#[serde(skip_serializing)]`
|
||||||
Meta(Path(ref word)) if word == SKIP_SERIALIZING => {
|
Meta(Path(word)) if word == SKIP_SERIALIZING => {
|
||||||
skip_serializing.set_true(word);
|
skip_serializing.set_true(word);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(skip_deserializing)]`
|
// Parse `#[serde(skip_deserializing)]`
|
||||||
Meta(Path(ref word)) if word == SKIP_DESERIALIZING => {
|
Meta(Path(word)) if word == SKIP_DESERIALIZING => {
|
||||||
skip_deserializing.set_true(word);
|
skip_deserializing.set_true(word);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(skip)]`
|
// Parse `#[serde(skip)]`
|
||||||
Meta(Path(ref word)) if word == SKIP => {
|
Meta(Path(word)) if word == SKIP => {
|
||||||
skip_serializing.set_true(word);
|
skip_serializing.set_true(word);
|
||||||
skip_deserializing.set_true(word);
|
skip_deserializing.set_true(word);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(skip_serializing_if = "...")]`
|
// Parse `#[serde(skip_serializing_if = "...")]`
|
||||||
Meta(NameValue(ref m)) if m.path == SKIP_SERIALIZING_IF => {
|
Meta(NameValue(m)) if m.path == SKIP_SERIALIZING_IF => {
|
||||||
if let Ok(path) = parse_lit_into_expr_path(cx, SKIP_SERIALIZING_IF, &m.lit) {
|
if let Ok(path) = parse_lit_into_expr_path(cx, SKIP_SERIALIZING_IF, &m.lit) {
|
||||||
skip_serializing_if.set(&m.path, path);
|
skip_serializing_if.set(&m.path, path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(serialize_with = "...")]`
|
// Parse `#[serde(serialize_with = "...")]`
|
||||||
Meta(NameValue(ref m)) if m.path == SERIALIZE_WITH => {
|
Meta(NameValue(m)) if m.path == SERIALIZE_WITH => {
|
||||||
if let Ok(path) = parse_lit_into_expr_path(cx, SERIALIZE_WITH, &m.lit) {
|
if let Ok(path) = parse_lit_into_expr_path(cx, SERIALIZE_WITH, &m.lit) {
|
||||||
serialize_with.set(&m.path, path);
|
serialize_with.set(&m.path, path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(deserialize_with = "...")]`
|
// Parse `#[serde(deserialize_with = "...")]`
|
||||||
Meta(NameValue(ref m)) if m.path == DESERIALIZE_WITH => {
|
Meta(NameValue(m)) if m.path == DESERIALIZE_WITH => {
|
||||||
if let Ok(path) = parse_lit_into_expr_path(cx, DESERIALIZE_WITH, &m.lit) {
|
if let Ok(path) = parse_lit_into_expr_path(cx, DESERIALIZE_WITH, &m.lit) {
|
||||||
deserialize_with.set(&m.path, path);
|
deserialize_with.set(&m.path, path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(with = "...")]`
|
// Parse `#[serde(with = "...")]`
|
||||||
Meta(NameValue(ref m)) if m.path == WITH => {
|
Meta(NameValue(m)) if m.path == WITH => {
|
||||||
if let Ok(path) = parse_lit_into_expr_path(cx, WITH, &m.lit) {
|
if let Ok(path) = parse_lit_into_expr_path(cx, WITH, &m.lit) {
|
||||||
let mut ser_path = path.clone();
|
let mut ser_path = path.clone();
|
||||||
ser_path
|
ser_path
|
||||||
@@ -1315,7 +1277,7 @@ impl Field {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(bound = "T: SomeBound")]`
|
// Parse `#[serde(bound = "T: SomeBound")]`
|
||||||
Meta(NameValue(ref m)) if m.path == BOUND => {
|
Meta(NameValue(m)) if m.path == BOUND => {
|
||||||
if let Ok(where_predicates) = parse_lit_into_where(cx, BOUND, BOUND, &m.lit) {
|
if let Ok(where_predicates) = parse_lit_into_where(cx, BOUND, BOUND, &m.lit) {
|
||||||
ser_bound.set(&m.path, where_predicates.clone());
|
ser_bound.set(&m.path, where_predicates.clone());
|
||||||
de_bound.set(&m.path, where_predicates);
|
de_bound.set(&m.path, where_predicates);
|
||||||
@@ -1323,7 +1285,7 @@ impl Field {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(bound(serialize = "...", deserialize = "..."))]`
|
// Parse `#[serde(bound(serialize = "...", deserialize = "..."))]`
|
||||||
Meta(List(ref m)) if m.path == BOUND => {
|
Meta(List(m)) if m.path == BOUND => {
|
||||||
if let Ok((ser, de)) = get_where_predicates(cx, &m.nested) {
|
if let Ok((ser, de)) = get_where_predicates(cx, &m.nested) {
|
||||||
ser_bound.set_opt(&m.path, ser);
|
ser_bound.set_opt(&m.path, ser);
|
||||||
de_bound.set_opt(&m.path, de);
|
de_bound.set_opt(&m.path, de);
|
||||||
@@ -1331,14 +1293,14 @@ impl Field {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(borrow)]`
|
// Parse `#[serde(borrow)]`
|
||||||
Meta(Path(ref word)) if word == BORROW => {
|
Meta(Path(word)) if word == BORROW => {
|
||||||
if let Ok(borrowable) = borrowable_lifetimes(cx, &ident, field) {
|
if let Ok(borrowable) = borrowable_lifetimes(cx, &ident, field) {
|
||||||
borrowed_lifetimes.set(word, borrowable);
|
borrowed_lifetimes.set(word, borrowable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(borrow = "'a + 'b")]`
|
// Parse `#[serde(borrow = "'a + 'b")]`
|
||||||
Meta(NameValue(ref m)) if m.path == BORROW => {
|
Meta(NameValue(m)) if m.path == BORROW => {
|
||||||
if let Ok(lifetimes) = parse_lit_into_lifetimes(cx, BORROW, &m.lit) {
|
if let Ok(lifetimes) = parse_lit_into_lifetimes(cx, BORROW, &m.lit) {
|
||||||
if let Ok(borrowable) = borrowable_lifetimes(cx, &ident, field) {
|
if let Ok(borrowable) = borrowable_lifetimes(cx, &ident, field) {
|
||||||
for lifetime in &lifetimes {
|
for lifetime in &lifetimes {
|
||||||
@@ -1358,18 +1320,18 @@ impl Field {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(getter = "...")]`
|
// Parse `#[serde(getter = "...")]`
|
||||||
Meta(NameValue(ref m)) if m.path == GETTER => {
|
Meta(NameValue(m)) if m.path == GETTER => {
|
||||||
if let Ok(path) = parse_lit_into_expr_path(cx, GETTER, &m.lit) {
|
if let Ok(path) = parse_lit_into_expr_path(cx, GETTER, &m.lit) {
|
||||||
getter.set(&m.path, path);
|
getter.set(&m.path, path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(flatten)]`
|
// Parse `#[serde(flatten)]`
|
||||||
Meta(Path(ref word)) if word == FLATTEN => {
|
Meta(Path(word)) if word == FLATTEN => {
|
||||||
flatten.set_true(word);
|
flatten.set_true(word);
|
||||||
}
|
}
|
||||||
|
|
||||||
Meta(ref meta_item) => {
|
Meta(meta_item) => {
|
||||||
let path = meta_item
|
let path = meta_item
|
||||||
.path()
|
.path()
|
||||||
.into_token_stream()
|
.into_token_stream()
|
||||||
@@ -1381,7 +1343,7 @@ impl Field {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Lit(ref lit) => {
|
Lit(lit) => {
|
||||||
cx.error_spanned_by(lit, "unexpected literal in serde field attribute");
|
cx.error_spanned_by(lit, "unexpected literal in serde field attribute");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1551,14 +1513,14 @@ where
|
|||||||
let mut de_meta = VecAttr::none(cx, attr_name);
|
let mut de_meta = VecAttr::none(cx, attr_name);
|
||||||
|
|
||||||
for meta in metas {
|
for meta in metas {
|
||||||
match *meta {
|
match meta {
|
||||||
Meta(NameValue(ref meta)) if meta.path == SERIALIZE => {
|
Meta(NameValue(meta)) if meta.path == SERIALIZE => {
|
||||||
if let Ok(v) = f(cx, attr_name, SERIALIZE, &meta.lit) {
|
if let Ok(v) = f(cx, attr_name, SERIALIZE, &meta.lit) {
|
||||||
ser_meta.insert(&meta.path, v);
|
ser_meta.insert(&meta.path, v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Meta(NameValue(ref meta)) if meta.path == DESERIALIZE => {
|
Meta(NameValue(meta)) if meta.path == DESERIALIZE => {
|
||||||
if let Ok(v) = f(cx, attr_name, DESERIALIZE, &meta.lit) {
|
if let Ok(v) = f(cx, attr_name, DESERIALIZE, &meta.lit) {
|
||||||
de_meta.insert(&meta.path, v);
|
de_meta.insert(&meta.path, v);
|
||||||
}
|
}
|
||||||
@@ -1610,7 +1572,7 @@ pub fn get_serde_meta_items(cx: &Ctxt, attr: &syn::Attribute) -> Result<Vec<syn:
|
|||||||
}
|
}
|
||||||
|
|
||||||
match attr.parse_meta() {
|
match attr.parse_meta() {
|
||||||
Ok(List(ref meta)) => Ok(meta.nested.iter().cloned().collect()),
|
Ok(List(meta)) => Ok(meta.nested.into_iter().collect()),
|
||||||
Ok(other) => {
|
Ok(other) => {
|
||||||
cx.error_spanned_by(other, "expected #[serde(...)]");
|
cx.error_spanned_by(other, "expected #[serde(...)]");
|
||||||
Err(())
|
Err(())
|
||||||
@@ -1632,7 +1594,7 @@ fn get_lit_str2<'a>(
|
|||||||
meta_item_name: Symbol,
|
meta_item_name: Symbol,
|
||||||
lit: &'a syn::Lit,
|
lit: &'a syn::Lit,
|
||||||
) -> Result<&'a syn::LitStr, ()> {
|
) -> Result<&'a syn::LitStr, ()> {
|
||||||
if let syn::Lit::Str(ref lit) = *lit {
|
if let syn::Lit::Str(lit) = lit {
|
||||||
Ok(lit)
|
Ok(lit)
|
||||||
} else {
|
} else {
|
||||||
cx.error_spanned_by(
|
cx.error_spanned_by(
|
||||||
@@ -1762,8 +1724,8 @@ fn is_implicitly_borrowed_reference(ty: &syn::Type) -> bool {
|
|||||||
// cow: Cow<'a, str>,
|
// cow: Cow<'a, str>,
|
||||||
// }
|
// }
|
||||||
fn is_cow(ty: &syn::Type, elem: fn(&syn::Type) -> bool) -> bool {
|
fn is_cow(ty: &syn::Type, elem: fn(&syn::Type) -> bool) -> bool {
|
||||||
let path = match *ty {
|
let path = match ty {
|
||||||
syn::Type::Path(ref ty) => &ty.path,
|
syn::Type::Path(ty) => &ty.path,
|
||||||
_ => {
|
_ => {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -1774,8 +1736,8 @@ fn is_cow(ty: &syn::Type, elem: fn(&syn::Type) -> bool) -> bool {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let args = match seg.arguments {
|
let args = match &seg.arguments {
|
||||||
syn::PathArguments::AngleBracketed(ref bracketed) => &bracketed.args,
|
syn::PathArguments::AngleBracketed(bracketed) => &bracketed.args,
|
||||||
_ => {
|
_ => {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -1783,14 +1745,14 @@ fn is_cow(ty: &syn::Type, elem: fn(&syn::Type) -> bool) -> bool {
|
|||||||
seg.ident == "Cow"
|
seg.ident == "Cow"
|
||||||
&& args.len() == 2
|
&& args.len() == 2
|
||||||
&& match (&args[0], &args[1]) {
|
&& match (&args[0], &args[1]) {
|
||||||
(&syn::GenericArgument::Lifetime(_), &syn::GenericArgument::Type(ref arg)) => elem(arg),
|
(syn::GenericArgument::Lifetime(_), syn::GenericArgument::Type(arg)) => elem(arg),
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_option(ty: &syn::Type, elem: fn(&syn::Type) -> bool) -> bool {
|
fn is_option(ty: &syn::Type, elem: fn(&syn::Type) -> bool) -> bool {
|
||||||
let path = match *ty {
|
let path = match ty {
|
||||||
syn::Type::Path(ref ty) => &ty.path,
|
syn::Type::Path(ty) => &ty.path,
|
||||||
_ => {
|
_ => {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -1801,16 +1763,16 @@ fn is_option(ty: &syn::Type, elem: fn(&syn::Type) -> bool) -> bool {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let args = match seg.arguments {
|
let args = match &seg.arguments {
|
||||||
syn::PathArguments::AngleBracketed(ref bracketed) => &bracketed.args,
|
syn::PathArguments::AngleBracketed(bracketed) => &bracketed.args,
|
||||||
_ => {
|
_ => {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
seg.ident == "Option"
|
seg.ident == "Option"
|
||||||
&& args.len() == 1
|
&& args.len() == 1
|
||||||
&& match args[0] {
|
&& match &args[0] {
|
||||||
syn::GenericArgument::Type(ref arg) => elem(arg),
|
syn::GenericArgument::Type(arg) => elem(arg),
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1836,8 +1798,8 @@ fn is_option(ty: &syn::Type, elem: fn(&syn::Type) -> bool) -> bool {
|
|||||||
// r: &'a str,
|
// r: &'a str,
|
||||||
// }
|
// }
|
||||||
fn is_reference(ty: &syn::Type, elem: fn(&syn::Type) -> bool) -> bool {
|
fn is_reference(ty: &syn::Type, elem: fn(&syn::Type) -> bool) -> bool {
|
||||||
match *ty {
|
match ty {
|
||||||
syn::Type::Reference(ref ty) => ty.mutability.is_none() && elem(&ty.elem),
|
syn::Type::Reference(ty) => ty.mutability.is_none() && elem(&ty.elem),
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1847,15 +1809,15 @@ fn is_str(ty: &syn::Type) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn is_slice_u8(ty: &syn::Type) -> bool {
|
fn is_slice_u8(ty: &syn::Type) -> bool {
|
||||||
match *ty {
|
match ty {
|
||||||
syn::Type::Slice(ref ty) => is_primitive_type(&ty.elem, "u8"),
|
syn::Type::Slice(ty) => is_primitive_type(&ty.elem, "u8"),
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_primitive_type(ty: &syn::Type, primitive: &str) -> bool {
|
fn is_primitive_type(ty: &syn::Type, primitive: &str) -> bool {
|
||||||
match *ty {
|
match ty {
|
||||||
syn::Type::Path(ref ty) => ty.qself.is_none() && is_primitive_path(&ty.path, primitive),
|
syn::Type::Path(ty) => ty.qself.is_none() && is_primitive_path(&ty.path, primitive),
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1893,40 +1855,40 @@ fn borrowable_lifetimes(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn collect_lifetimes(ty: &syn::Type, out: &mut BTreeSet<syn::Lifetime>) {
|
fn collect_lifetimes(ty: &syn::Type, out: &mut BTreeSet<syn::Lifetime>) {
|
||||||
match *ty {
|
match ty {
|
||||||
syn::Type::Slice(ref ty) => {
|
syn::Type::Slice(ty) => {
|
||||||
collect_lifetimes(&ty.elem, out);
|
collect_lifetimes(&ty.elem, out);
|
||||||
}
|
}
|
||||||
syn::Type::Array(ref ty) => {
|
syn::Type::Array(ty) => {
|
||||||
collect_lifetimes(&ty.elem, out);
|
collect_lifetimes(&ty.elem, out);
|
||||||
}
|
}
|
||||||
syn::Type::Ptr(ref ty) => {
|
syn::Type::Ptr(ty) => {
|
||||||
collect_lifetimes(&ty.elem, out);
|
collect_lifetimes(&ty.elem, out);
|
||||||
}
|
}
|
||||||
syn::Type::Reference(ref ty) => {
|
syn::Type::Reference(ty) => {
|
||||||
out.extend(ty.lifetime.iter().cloned());
|
out.extend(ty.lifetime.iter().cloned());
|
||||||
collect_lifetimes(&ty.elem, out);
|
collect_lifetimes(&ty.elem, out);
|
||||||
}
|
}
|
||||||
syn::Type::Tuple(ref ty) => {
|
syn::Type::Tuple(ty) => {
|
||||||
for elem in &ty.elems {
|
for elem in &ty.elems {
|
||||||
collect_lifetimes(elem, out);
|
collect_lifetimes(elem, out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
syn::Type::Path(ref ty) => {
|
syn::Type::Path(ty) => {
|
||||||
if let Some(ref qself) = ty.qself {
|
if let Some(qself) = &ty.qself {
|
||||||
collect_lifetimes(&qself.ty, out);
|
collect_lifetimes(&qself.ty, out);
|
||||||
}
|
}
|
||||||
for seg in &ty.path.segments {
|
for seg in &ty.path.segments {
|
||||||
if let syn::PathArguments::AngleBracketed(ref bracketed) = seg.arguments {
|
if let syn::PathArguments::AngleBracketed(bracketed) = &seg.arguments {
|
||||||
for arg in &bracketed.args {
|
for arg in &bracketed.args {
|
||||||
match *arg {
|
match arg {
|
||||||
syn::GenericArgument::Lifetime(ref lifetime) => {
|
syn::GenericArgument::Lifetime(lifetime) => {
|
||||||
out.insert(lifetime.clone());
|
out.insert(lifetime.clone());
|
||||||
}
|
}
|
||||||
syn::GenericArgument::Type(ref ty) => {
|
syn::GenericArgument::Type(ty) => {
|
||||||
collect_lifetimes(ty, out);
|
collect_lifetimes(ty, out);
|
||||||
}
|
}
|
||||||
syn::GenericArgument::Binding(ref binding) => {
|
syn::GenericArgument::Binding(binding) => {
|
||||||
collect_lifetimes(&binding.ty, out);
|
collect_lifetimes(&binding.ty, out);
|
||||||
}
|
}
|
||||||
syn::GenericArgument::Constraint(_)
|
syn::GenericArgument::Constraint(_)
|
||||||
@@ -1936,10 +1898,10 @@ fn collect_lifetimes(ty: &syn::Type, out: &mut BTreeSet<syn::Lifetime>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
syn::Type::Paren(ref ty) => {
|
syn::Type::Paren(ty) => {
|
||||||
collect_lifetimes(&ty.elem, out);
|
collect_lifetimes(&ty.elem, out);
|
||||||
}
|
}
|
||||||
syn::Type::Group(ref ty) => {
|
syn::Type::Group(ty) => {
|
||||||
collect_lifetimes(&ty.elem, out);
|
collect_lifetimes(&ty.elem, out);
|
||||||
}
|
}
|
||||||
syn::Type::BareFn(_)
|
syn::Type::BareFn(_)
|
||||||
@@ -1974,7 +1936,7 @@ fn respan_token_stream(stream: TokenStream, span: Span) -> TokenStream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn respan_token_tree(mut token: TokenTree, span: Span) -> TokenTree {
|
fn respan_token_tree(mut token: TokenTree, span: Span) -> TokenTree {
|
||||||
if let TokenTree::Group(ref mut g) = token {
|
if let TokenTree::Group(g) = &mut token {
|
||||||
*g = Group::new(g.delimiter(), respan_token_stream(g.stream().clone(), span));
|
*g = Group::new(g.delimiter(), respan_token_stream(g.stream().clone(), span));
|
||||||
}
|
}
|
||||||
token.set_span(span);
|
token.set_span(span);
|
||||||
|
|||||||
@@ -41,17 +41,17 @@ fn check_getter(cx: &Ctxt, cont: &Container) {
|
|||||||
|
|
||||||
/// Flattening has some restrictions we can test.
|
/// Flattening has some restrictions we can test.
|
||||||
fn check_flatten(cx: &Ctxt, cont: &Container) {
|
fn check_flatten(cx: &Ctxt, cont: &Container) {
|
||||||
match cont.data {
|
match &cont.data {
|
||||||
Data::Enum(ref variants) => {
|
Data::Enum(variants) => {
|
||||||
for variant in variants {
|
for variant in variants {
|
||||||
for field in &variant.fields {
|
for field in &variant.fields {
|
||||||
check_flatten_field(cx, variant.style, field);
|
check_flatten_field(cx, variant.style, field);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Data::Struct(style, ref fields) => {
|
Data::Struct(style, fields) => {
|
||||||
for field in fields {
|
for field in fields {
|
||||||
check_flatten_field(cx, style, field);
|
check_flatten_field(cx, *style, field);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -85,8 +85,8 @@ fn check_flatten_field(cx: &Ctxt, style: Style, field: &Field) {
|
|||||||
/// `field_identifier` all but possibly one variant must be unit variants. The
|
/// `field_identifier` all but possibly one variant must be unit variants. The
|
||||||
/// last variant may be a newtype variant which is an implicit "other" case.
|
/// last variant may be a newtype variant which is an implicit "other" case.
|
||||||
fn check_identifier(cx: &Ctxt, cont: &Container) {
|
fn check_identifier(cx: &Ctxt, cont: &Container) {
|
||||||
let variants = match cont.data {
|
let variants = match &cont.data {
|
||||||
Data::Enum(ref variants) => variants,
|
Data::Enum(variants) => variants,
|
||||||
Data::Struct(_, _) => {
|
Data::Struct(_, _) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -169,8 +169,8 @@ fn check_identifier(cx: &Ctxt, cont: &Container) {
|
|||||||
/// Skip-(de)serializing attributes are not allowed on variants marked
|
/// Skip-(de)serializing attributes are not allowed on variants marked
|
||||||
/// (de)serialize_with.
|
/// (de)serialize_with.
|
||||||
fn check_variant_skip_attrs(cx: &Ctxt, cont: &Container) {
|
fn check_variant_skip_attrs(cx: &Ctxt, cont: &Container) {
|
||||||
let variants = match cont.data {
|
let variants = match &cont.data {
|
||||||
Data::Enum(ref variants) => variants,
|
Data::Enum(variants) => variants,
|
||||||
Data::Struct(_, _) => {
|
Data::Struct(_, _) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -246,13 +246,13 @@ fn check_variant_skip_attrs(cx: &Ctxt, cont: &Container) {
|
|||||||
/// duplicate keys in the serialized output and/or ambiguity in
|
/// duplicate keys in the serialized output and/or ambiguity in
|
||||||
/// the to-be-deserialized input.
|
/// the to-be-deserialized input.
|
||||||
fn check_internal_tag_field_name_conflict(cx: &Ctxt, cont: &Container) {
|
fn check_internal_tag_field_name_conflict(cx: &Ctxt, cont: &Container) {
|
||||||
let variants = match cont.data {
|
let variants = match &cont.data {
|
||||||
Data::Enum(ref variants) => variants,
|
Data::Enum(variants) => variants,
|
||||||
Data::Struct(_, _) => return,
|
Data::Struct(_, _) => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
let tag = match *cont.attrs.tag() {
|
let tag = match cont.attrs.tag() {
|
||||||
TagType::Internal { ref tag } => tag.as_str(),
|
TagType::Internal { tag } => tag.as_str(),
|
||||||
TagType::External | TagType::Adjacent { .. } | TagType::None => return,
|
TagType::External | TagType::Adjacent { .. } | TagType::None => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -293,11 +293,8 @@ fn check_internal_tag_field_name_conflict(cx: &Ctxt, cont: &Container) {
|
|||||||
/// In the case of adjacently-tagged enums, the type and the
|
/// In the case of adjacently-tagged enums, the type and the
|
||||||
/// contents tag must differ, for the same reason.
|
/// contents tag must differ, for the same reason.
|
||||||
fn check_adjacent_tag_conflict(cx: &Ctxt, cont: &Container) {
|
fn check_adjacent_tag_conflict(cx: &Ctxt, cont: &Container) {
|
||||||
let (type_tag, content_tag) = match *cont.attrs.tag() {
|
let (type_tag, content_tag) = match cont.attrs.tag() {
|
||||||
TagType::Adjacent {
|
TagType::Adjacent { tag, content } => (tag, content),
|
||||||
ref tag,
|
|
||||||
ref content,
|
|
||||||
} => (tag, content),
|
|
||||||
TagType::Internal { .. } | TagType::External | TagType::None => return,
|
TagType::Internal { .. } | TagType::External | TagType::None => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -339,7 +336,7 @@ fn check_transparent(cx: &Ctxt, cont: &mut Container, derive: Derive) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let fields = match cont.data {
|
let fields = match &mut cont.data {
|
||||||
Data::Enum(_) => {
|
Data::Enum(_) => {
|
||||||
cx.error_spanned_by(
|
cx.error_spanned_by(
|
||||||
cont.original,
|
cont.original,
|
||||||
@@ -354,7 +351,7 @@ fn check_transparent(cx: &Ctxt, cont: &mut Container, derive: Derive) {
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Data::Struct(_, ref mut fields) => fields,
|
Data::Struct(_, fields) => fields,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut transparent_field = None;
|
let mut transparent_field = None;
|
||||||
@@ -392,14 +389,14 @@ fn check_transparent(cx: &Ctxt, cont: &mut Container, derive: Derive) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn member_message(member: &Member) -> String {
|
fn member_message(member: &Member) -> String {
|
||||||
match *member {
|
match member {
|
||||||
Member::Named(ref ident) => format!("`{}`", ident),
|
Member::Named(ident) => format!("`{}`", ident),
|
||||||
Member::Unnamed(ref i) => format!("#{}", i.index),
|
Member::Unnamed(i) => format!("#{}", i.index),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn allow_transparent(field: &Field, derive: Derive) -> bool {
|
fn allow_transparent(field: &Field, derive: Derive) -> bool {
|
||||||
if let Type::Path(ref ty) = *field.ty {
|
if let Type::Path(ty) = field.ty {
|
||||||
if let Some(seg) = ty.path.segments.last() {
|
if let Some(seg) = ty.path.segments.last() {
|
||||||
if seg.ident == "PhantomData" {
|
if seg.ident == "PhantomData" {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -52,8 +52,8 @@ fn pretend_fields_used(cont: &Container) -> TokenStream {
|
|||||||
let type_ident = &cont.ident;
|
let type_ident = &cont.ident;
|
||||||
let (_, ty_generics, _) = cont.generics.split_for_impl();
|
let (_, ty_generics, _) = cont.generics.split_for_impl();
|
||||||
|
|
||||||
let patterns = match cont.data {
|
let patterns = match &cont.data {
|
||||||
Data::Enum(ref variants) => variants
|
Data::Enum(variants) => variants
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|variant| match variant.style {
|
.filter_map(|variant| match variant.style {
|
||||||
Style::Struct => {
|
Style::Struct => {
|
||||||
@@ -64,7 +64,7 @@ fn pretend_fields_used(cont: &Container) -> TokenStream {
|
|||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
Data::Struct(Style::Struct, ref fields) => {
|
Data::Struct(Style::Struct, fields) => {
|
||||||
let pat = struct_pattern(fields);
|
let pat = struct_pattern(fields);
|
||||||
vec![quote!(#type_ident #pat)]
|
vec![quote!(#type_ident #pat)]
|
||||||
}
|
}
|
||||||
@@ -93,8 +93,8 @@ fn pretend_fields_used(cont: &Container) -> TokenStream {
|
|||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
fn pretend_variants_used(cont: &Container) -> TokenStream {
|
fn pretend_variants_used(cont: &Container) -> TokenStream {
|
||||||
let variants = match cont.data {
|
let variants = match &cont.data {
|
||||||
Data::Enum(ref variants) => variants,
|
Data::Enum(variants) => variants,
|
||||||
Data::Struct(_, _) => {
|
Data::Struct(_, _) => {
|
||||||
return quote!();
|
return quote!();
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-23
@@ -164,15 +164,13 @@ fn serialize_body(cont: &Container, params: &Parameters) -> Fragment {
|
|||||||
} else if let Some(type_into) = cont.attrs.type_into() {
|
} else if let Some(type_into) = cont.attrs.type_into() {
|
||||||
serialize_into(params, type_into)
|
serialize_into(params, type_into)
|
||||||
} else {
|
} else {
|
||||||
match cont.data {
|
match &cont.data {
|
||||||
Data::Enum(ref variants) => serialize_enum(params, variants, &cont.attrs),
|
Data::Enum(variants) => serialize_enum(params, variants, &cont.attrs),
|
||||||
Data::Struct(Style::Struct, ref fields) => {
|
Data::Struct(Style::Struct, fields) => serialize_struct(params, fields, &cont.attrs),
|
||||||
serialize_struct(params, fields, &cont.attrs)
|
Data::Struct(Style::Tuple, fields) => {
|
||||||
}
|
|
||||||
Data::Struct(Style::Tuple, ref fields) => {
|
|
||||||
serialize_tuple_struct(params, fields, &cont.attrs)
|
serialize_tuple_struct(params, fields, &cont.attrs)
|
||||||
}
|
}
|
||||||
Data::Struct(Style::Newtype, ref fields) => {
|
Data::Struct(Style::Newtype, fields) => {
|
||||||
serialize_newtype_struct(params, &fields[0], &cont.attrs)
|
serialize_newtype_struct(params, &fields[0], &cont.attrs)
|
||||||
}
|
}
|
||||||
Data::Struct(Style::Unit, _) => serialize_unit_struct(&cont.attrs),
|
Data::Struct(Style::Unit, _) => serialize_unit_struct(&cont.attrs),
|
||||||
@@ -181,8 +179,8 @@ fn serialize_body(cont: &Container, params: &Parameters) -> Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_transparent(cont: &Container, params: &Parameters) -> Fragment {
|
fn serialize_transparent(cont: &Container, params: &Parameters) -> Fragment {
|
||||||
let fields = match cont.data {
|
let fields = match &cont.data {
|
||||||
Data::Struct(_, ref fields) => fields,
|
Data::Struct(_, fields) => fields,
|
||||||
Data::Enum(_) => unreachable!(),
|
Data::Enum(_) => unreachable!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -259,7 +257,7 @@ fn serialize_tuple_struct(
|
|||||||
let mut serialized_fields = fields
|
let mut serialized_fields = fields
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.filter(|&(_, ref field)| !field.attrs.skip_serializing())
|
.filter(|(_, field)| !field.attrs.skip_serializing())
|
||||||
.peekable();
|
.peekable();
|
||||||
|
|
||||||
let let_mut = mut_if(serialized_fields.peek().is_some());
|
let let_mut = mut_if(serialized_fields.peek().is_some());
|
||||||
@@ -296,8 +294,8 @@ fn serialize_struct(params: &Parameters, fields: &[Field], cattrs: &attr::Contai
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_struct_tag_field(cattrs: &attr::Container, struct_trait: &StructTrait) -> TokenStream {
|
fn serialize_struct_tag_field(cattrs: &attr::Container, struct_trait: &StructTrait) -> TokenStream {
|
||||||
match *cattrs.tag() {
|
match cattrs.tag() {
|
||||||
attr::TagType::Internal { ref tag } => {
|
attr::TagType::Internal { tag } => {
|
||||||
let type_name = cattrs.name().serialize_name();
|
let type_name = cattrs.name().serialize_name();
|
||||||
let func = struct_trait.serialize_field(Span::call_site());
|
let func = struct_trait.serialize_field(Span::call_site());
|
||||||
quote! {
|
quote! {
|
||||||
@@ -467,17 +465,16 @@ fn serialize_variant(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let body = Match(match *cattrs.tag() {
|
let body = Match(match cattrs.tag() {
|
||||||
attr::TagType::External => {
|
attr::TagType::External => {
|
||||||
serialize_externally_tagged_variant(params, variant, variant_index, cattrs)
|
serialize_externally_tagged_variant(params, variant, variant_index, cattrs)
|
||||||
}
|
}
|
||||||
attr::TagType::Internal { ref tag } => {
|
attr::TagType::Internal { tag } => {
|
||||||
serialize_internally_tagged_variant(params, variant, cattrs, tag)
|
serialize_internally_tagged_variant(params, variant, cattrs, tag)
|
||||||
}
|
}
|
||||||
attr::TagType::Adjacent {
|
attr::TagType::Adjacent { tag, content } => {
|
||||||
ref tag,
|
serialize_adjacently_tagged_variant(params, variant, cattrs, tag, content)
|
||||||
ref content,
|
}
|
||||||
} => serialize_adjacently_tagged_variant(params, variant, cattrs, tag, content),
|
|
||||||
attr::TagType::None => serialize_untagged_variant(params, variant, cattrs),
|
attr::TagType::None => serialize_untagged_variant(params, variant, cattrs),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -804,7 +801,7 @@ fn serialize_tuple_variant(
|
|||||||
let mut serialized_fields = fields
|
let mut serialized_fields = fields
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.filter(|&(_, ref field)| !field.attrs.skip_serializing())
|
.filter(|(_, field)| !field.attrs.skip_serializing())
|
||||||
.peekable();
|
.peekable();
|
||||||
|
|
||||||
let let_mut = mut_if(serialized_fields.peek().is_some());
|
let let_mut = mut_if(serialized_fields.peek().is_some());
|
||||||
@@ -1039,7 +1036,7 @@ fn serialize_tuple_struct_visitor(
|
|||||||
fields
|
fields
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.filter(|&(_, ref field)| !field.attrs.skip_serializing())
|
.filter(|(_, field)| !field.attrs.skip_serializing())
|
||||||
.map(|(i, field)| {
|
.map(|(i, field)| {
|
||||||
let mut field_expr = if is_enum {
|
let mut field_expr = if is_enum {
|
||||||
let id = Ident::new(&format!("__field{}", i), Span::call_site());
|
let id = Ident::new(&format!("__field{}", i), Span::call_site());
|
||||||
@@ -1163,9 +1160,9 @@ fn wrap_serialize_variant_with(
|
|||||||
.fields
|
.fields
|
||||||
.iter()
|
.iter()
|
||||||
.map(|field| {
|
.map(|field| {
|
||||||
let id = match field.member {
|
let id = match &field.member {
|
||||||
Member::Named(ref ident) => ident.clone(),
|
Member::Named(ident) => ident.clone(),
|
||||||
Member::Unnamed(ref member) => {
|
Member::Unnamed(member) => {
|
||||||
Ident::new(&format!("__field{}", member.index), Span::call_site())
|
Ident::new(&format!("__field{}", member.index), Span::call_site())
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user