Skip to content

Commit

Permalink
Implement ReflectValue serialization for Duration (#3318)
Browse files Browse the repository at this point in the history
# Objective

Resolves #3277 

Currenty if we try to serialize a scene that contains a `Duration` (which is very common, since `Timer` contains one), we get an error saying:

> Type 'core::time::Duration' does not support ReflectValue serialization


## Solution

Let `Duration` implement `SerializeValue`.



Co-authored-by: Jonathan Cornaz <[email protected]>
  • Loading branch information
jcornaz and jcornaz committed Dec 29, 2021
1 parent 8a8293b commit d07c8a8
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion crates/bevy_reflect/src/impls/std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl_reflect_value!(String(Hash, PartialEq, Serialize, Deserialize));
impl_reflect_value!(Option<T: Serialize + Clone + for<'de> Deserialize<'de> + Reflect + 'static>(Serialize, Deserialize));
impl_reflect_value!(HashSet<T: Serialize + Hash + Eq + Clone + for<'de> Deserialize<'de> + Send + Sync + 'static>(Serialize, Deserialize));
impl_reflect_value!(Range<T: Serialize + Clone + for<'de> Deserialize<'de> + Send + Sync + 'static>(Serialize, Deserialize));
impl_reflect_value!(Duration);
impl_reflect_value!(Duration(Hash, PartialEq, Serialize, Deserialize));

impl_from_reflect_value!(bool);
impl_from_reflect_value!(u8);
Expand Down Expand Up @@ -364,3 +364,13 @@ impl FromReflect for Cow<'static, str> {
Some(reflect.any().downcast_ref::<Cow<'static, str>>()?.clone())
}
}

#[cfg(test)]
mod tests {
use crate::Reflect;

#[test]
fn can_serialize_duration() {
assert!(std::time::Duration::ZERO.serializable().is_some())
}
}

0 comments on commit d07c8a8

Please sign in to comment.