Skip to content

Commit

Permalink
Make use of the Cow
Browse files Browse the repository at this point in the history
  • Loading branch information
MrGVSV committed Dec 10, 2022
1 parent 755185b commit 2200596
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion crates/bevy_reflect/src/serde/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use serde::de::{
};
use serde::Deserialize;
use std::any::TypeId;
use std::borrow::Cow;
use std::fmt;
use std::fmt::{Debug, Display, Formatter};
use std::slice::Iter;
Expand Down Expand Up @@ -273,7 +274,7 @@ impl<'a, 'de> Visitor<'de> for UntypedReflectDeserializerVisitor<'a> {
A: MapAccess<'de>,
{
let type_name = map
.next_key::<String>()?
.next_key::<Cow<'static, str>>()?
.ok_or_else(|| Error::invalid_length(0, &"at least one entry"))?;

let registration = self.registry.get_with_name(&type_name).ok_or_else(|| {
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_scene/src/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use serde::{
ser::SerializeStruct,
Deserialize, Deserializer, Serialize, Serializer,
};
use std::borrow::Cow;
use std::fmt::Formatter;

pub const SCENE_STRUCT: &str = "Scene";
Expand Down Expand Up @@ -352,7 +353,7 @@ impl<'a, 'de> Visitor<'de> for ComponentVisitor<'a> {
{
let mut added = HashSet::new();
let mut components = Vec::new();
while let Some(key) = map.next_key::<String>()? {
while let Some(key) = map.next_key::<Cow<'static, str>>()? {
if !added.insert(key.clone()) {
return Err(Error::custom(format!("duplicate component: `{key}`")));
}
Expand Down

0 comments on commit 2200596

Please sign in to comment.