diff --git a/serde_derive/src/de.rs b/serde_derive/src/de.rs index 59cc173d6..2308ecd27 100644 --- a/serde_derive/src/de.rs +++ b/serde_derive/src/de.rs @@ -1040,7 +1040,7 @@ fn deserialize_struct( } else { let field_names = field_names_idents .iter() - .flat_map(|(_, _, aliases)| aliases); + .flat_map(|&(_, _, aliases)| aliases); Some(quote! { #[doc(hidden)] @@ -1162,7 +1162,7 @@ fn deserialize_struct_in_place( let visit_map = Stmts(deserialize_map_in_place(params, fields, cattrs)); let field_names = field_names_idents .iter() - .flat_map(|(_, _, aliases)| aliases); + .flat_map(|&(_, _, aliases)| aliases); let type_name = cattrs.name().deserialize_name(); let in_place_impl_generics = de_impl_generics.in_place(); @@ -2001,7 +2001,7 @@ fn deserialize_untagged_newtype_variant( } fn deserialize_generated_identifier( - fields: &[(String, Ident, Vec)], + fields: &[(&str, Ident, &[String])], cattrs: &attr::Container, is_variant: bool, other_idx: Option, @@ -2131,7 +2131,7 @@ fn deserialize_custom_identifier( }) .collect(); - let names = names_idents.iter().flat_map(|(_, _, aliases)| aliases); + let names = names_idents.iter().flat_map(|&(_, _, aliases)| aliases); let names_const = if fallthrough.is_some() { None @@ -2187,7 +2187,7 @@ fn deserialize_custom_identifier( fn deserialize_identifier( this_value: &TokenStream, - fields: &[(String, Ident, Vec)], + fields: &[(&str, Ident, &[String])], is_variant: bool, fallthrough: Option, fallthrough_borrowed: Option, diff --git a/serde_derive/src/internals/attr.rs b/serde_derive/src/internals/attr.rs index c96d0a834..fea90aadb 100644 --- a/serde_derive/src/internals/attr.rs +++ b/serde_derive/src/internals/attr.rs @@ -173,17 +173,17 @@ impl Name { } /// Return the container name for the container when serializing. - pub fn serialize_name(&self) -> String { - self.serialize.clone() + pub fn serialize_name(&self) -> &str { + &self.serialize } /// Return the container name for the container when deserializing. - pub fn deserialize_name(&self) -> String { - self.deserialize.clone() + pub fn deserialize_name(&self) -> &str { + &self.deserialize } - fn deserialize_aliases(&self) -> Vec { - self.deserialize_aliases.clone() + fn deserialize_aliases(&self) -> &[String] { + &self.deserialize_aliases } fn insert_deserialize_name_into_aliases(&mut self) { @@ -986,7 +986,7 @@ impl Variant { &self.name } - pub fn aliases(&self) -> Vec { + pub fn aliases(&self) -> &[String] { self.name.deserialize_aliases() } @@ -1326,7 +1326,7 @@ impl Field { &self.name } - pub fn aliases(&self) -> Vec { + pub fn aliases(&self) -> &[String] { self.name.deserialize_aliases() } diff --git a/serde_derive/src/ser.rs b/serde_derive/src/ser.rs index d6aba7713..dc02466f5 100644 --- a/serde_derive/src/ser.rs +++ b/serde_derive/src/ser.rs @@ -566,7 +566,7 @@ fn serialize_externally_tagged_variant( }, params, &variant.fields, - &type_name, + type_name, ), } } @@ -631,7 +631,7 @@ fn serialize_internally_tagged_variant( StructVariant::InternallyTagged { tag, variant_name }, params, &variant.fields, - &type_name, + type_name, ), Style::Tuple => unreachable!("checked in serde_derive_internals"), } @@ -698,7 +698,7 @@ fn serialize_adjacently_tagged_variant( StructVariant::Untagged, params, &variant.fields, - &variant_name, + variant_name, ), } }); @@ -794,16 +794,16 @@ fn serialize_untagged_variant( Style::Tuple => serialize_tuple_variant(TupleVariant::Untagged, params, &variant.fields), Style::Struct => { let type_name = cattrs.name().serialize_name(); - serialize_struct_variant(StructVariant::Untagged, params, &variant.fields, &type_name) + serialize_struct_variant(StructVariant::Untagged, params, &variant.fields, type_name) } } } -enum TupleVariant { +enum TupleVariant<'a> { ExternallyTagged { - type_name: String, + type_name: &'a str, variant_index: u32, - variant_name: String, + variant_name: &'a str, }, Untagged, } @@ -870,11 +870,11 @@ fn serialize_tuple_variant( enum StructVariant<'a> { ExternallyTagged { variant_index: u32, - variant_name: String, + variant_name: &'a str, }, InternallyTagged { tag: &'a str, - variant_name: String, + variant_name: &'a str, }, Untagged, }