From 8b8df09a608846222a823c853d85f91cd470e933 Mon Sep 17 00:00:00 2001 From: Hennadii Chernyshchyk Date: Sat, 8 Oct 2022 17:02:21 +0000 Subject: [PATCH] Impl Reflect for PathBuf and OsString (#6193) # Objective `Reflect` impl is missing for `PathBuf` and `OsString`. Closes #6166. ## Solution Add implementations. --- ## Changelog ### Added `Reflect` impls for `PathBuf` and `OsString`. --- crates/bevy_reflect/src/impls/std.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/crates/bevy_reflect/src/impls/std.rs b/crates/bevy_reflect/src/impls/std.rs index 1d7acbabf096a1..6767c9d1c49b11 100644 --- a/crates/bevy_reflect/src/impls/std.rs +++ b/crates/bevy_reflect/src/impls/std.rs @@ -11,6 +11,8 @@ use crate::utility::{GenericTypeInfoCell, NonGenericTypeInfoCell}; use bevy_reflect_derive::{impl_from_reflect_value, impl_reflect_value}; use bevy_utils::{Duration, Instant}; use bevy_utils::{HashMap, HashSet}; +#[cfg(any(unix, windows))] +use std::ffi::OsString; use std::{ any::Any, borrow::Cow, @@ -20,6 +22,7 @@ use std::{ NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize, }, ops::{Range, RangeFrom, RangeFull, RangeInclusive, RangeTo, RangeToInclusive}, + path::PathBuf, }; impl_reflect_value!(bool(Debug, Hash, PartialEq, Serialize, Deserialize)); @@ -39,6 +42,7 @@ impl_reflect_value!(isize(Debug, Hash, PartialEq, Serialize, Deserialize)); impl_reflect_value!(f32(Debug, PartialEq, Serialize, Deserialize)); impl_reflect_value!(f64(Debug, PartialEq, Serialize, Deserialize)); impl_reflect_value!(String(Debug, Hash, PartialEq, Serialize, Deserialize)); +impl_reflect_value!(PathBuf(Debug, Hash, PartialEq, Serialize, Deserialize)); impl_reflect_value!(Result()); impl_reflect_value!(HashSet()); impl_reflect_value!(Range()); @@ -62,6 +66,11 @@ impl_reflect_value!(NonZeroU16(Debug, Hash, PartialEq, Serialize, Deserialize)); impl_reflect_value!(NonZeroU8(Debug, Hash, PartialEq, Serialize, Deserialize)); impl_reflect_value!(NonZeroI8(Debug, Hash, PartialEq, Serialize, Deserialize)); +// Only for platforms that can serialize it as in serde: +// https://github.com/serde-rs/serde/blob/3ffb86fc70efd3d329519e2dddfa306cc04f167c/serde/src/de/impls.rs#L1732 +#[cfg(any(unix, windows))] +impl_reflect_value!(OsString(Debug, Hash, PartialEq, Serialize, Deserialize)); + impl_from_reflect_value!(bool); impl_from_reflect_value!(char); impl_from_reflect_value!(u8);