Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/serde_valid/src/features/fluent/localize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl Localize for PropertyErrorsMap<crate::validation::Error> {
M: fluent::memoizer::MemoizerKind,
{
self.iter()
.map(|(property, error)| (property.to_string(), error.localize(bundle)))
.map(|(property, error)| ((*property).clone(), error.localize(bundle)))
.collect()
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/serde_valid/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down
6 changes: 4 additions & 2 deletions crates/serde_valid/src/validation/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -104,5 +106,5 @@ where
pub type VecErrors<E = crate::validation::Error> = Vec<E>;
pub type ItemErrorsMap<E> = IndexMap<usize, Errors<E>>;
pub type ItemVecErrorsMap<E> = IndexMap<usize, VecErrors<E>>;
pub type PropertyErrorsMap<E> = IndexMap<String, Errors<E>>;
pub type PropertyVecErrorsMap<E> = IndexMap<String, VecErrors<E>>;
pub type PropertyErrorsMap<E> = IndexMap<Cow<'static, str>, Errors<E>>;
pub type PropertyVecErrorsMap<E> = IndexMap<Cow<'static, str>, VecErrors<E>>;
2 changes: 1 addition & 1 deletion crates/serde_valid_derive/src/serde/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/serde_valid_derive/src/types/field/named.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading