diff --git a/crates/serde_valid/src/features/fluent/localize.rs b/crates/serde_valid/src/features/fluent/localize.rs index 8fdf01b..d2cd352 100644 --- a/crates/serde_valid/src/features/fluent/localize.rs +++ b/crates/serde_valid/src/features/fluent/localize.rs @@ -89,7 +89,7 @@ impl Localize for PropertyErrorsMap { M: fluent::memoizer::MemoizerKind, { self.iter() - .map(|(property, error)| (property.to_string(), error.localize(bundle))) + .map(|(property, error)| ((*property).clone(), error.localize(bundle))) .collect() } } diff --git a/crates/serde_valid/src/lib.rs b/crates/serde_valid/src/lib.rs index be26578..dc6fcce 100644 --- a/crates/serde_valid/src/lib.rs +++ b/crates/serde_valid/src/lib.rs @@ -586,7 +586,7 @@ pub use error::{ #[allow(unused_imports)] pub use features::*; use indexmap::IndexMap; -use std::collections::HashMap; +use std::{borrow::Cow, collections::HashMap}; pub use validation::{ ValidateEnumerate, ValidateExclusiveMaximum, ValidateExclusiveMinimum, ValidateMaxItems, ValidateMaxLength, ValidateMaxProperties, ValidateMaximum, ValidateMinItems, ValidateMinLength, @@ -661,7 +661,7 @@ where for (key, value) in self.iter() { if let Err(errors) = value.validate() { - items.insert(key.into(), errors); + items.insert(Cow::from(key.into()), errors); } } @@ -685,7 +685,7 @@ where for (key, value) in self.iter() { if let Err(errors) = value.validate() { - items.insert(key.into(), errors); + items.insert(Cow::from(key.into()), errors); } } diff --git a/crates/serde_valid/src/validation/error.rs b/crates/serde_valid/src/validation/error.rs index fe6c42c..dfd87a5 100644 --- a/crates/serde_valid/src/validation/error.rs +++ b/crates/serde_valid/src/validation/error.rs @@ -5,6 +5,8 @@ mod into_error; mod message; mod object_errors; +use std::borrow::Cow; + pub use crate::error::{ EnumerateError, ExclusiveMaximumError, ExclusiveMinimumError, MaxItemsError, MaxLengthError, MaxPropertiesError, MaximumError, MinItemsError, MinLengthError, MinPropertiesError, @@ -104,5 +106,5 @@ where pub type VecErrors = Vec; pub type ItemErrorsMap = IndexMap>; pub type ItemVecErrorsMap = IndexMap>; -pub type PropertyErrorsMap = IndexMap>; -pub type PropertyVecErrorsMap = IndexMap>; +pub type PropertyErrorsMap = IndexMap, Errors>; +pub type PropertyVecErrorsMap = IndexMap, VecErrors>; diff --git a/crates/serde_valid_derive/src/serde/rename.rs b/crates/serde_valid_derive/src/serde/rename.rs index b901600..429a58a 100644 --- a/crates/serde_valid_derive/src/serde/rename.rs +++ b/crates/serde_valid_derive/src/serde/rename.rs @@ -15,7 +15,7 @@ pub fn collect_serde_rename_map(fields: &syn::FieldsNamed) -> RenameMap { if let Some(rename) = find_rename_from_serde_attributes(attribute) { renames.insert( field.ident.to_token_stream().to_string(), - quote!(#rename.to_string()), + quote!(std::borrow::Cow::from(#rename)), ); } } diff --git a/crates/serde_valid_derive/src/types/field/named.rs b/crates/serde_valid_derive/src/types/field/named.rs index 1ccbd22..a7e47c0 100644 --- a/crates/serde_valid_derive/src/types/field/named.rs +++ b/crates/serde_valid_derive/src/types/field/named.rs @@ -33,7 +33,7 @@ impl Field for NamedField<'_> { fn key(&self) -> proc_macro2::TokenStream { let name = &self.name; - quote!(#name.to_string()) + quote!(std::borrow::Cow::from(#name)) } fn errors_variable(&self) -> proc_macro2::TokenStream {