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`.
This commit is contained in:
Hennadii Chernyshchyk 2022-10-08 17:02:21 +00:00
parent cf86f275a9
commit ca3e6e6797

View file

@ -11,6 +11,8 @@ use crate::utility::{GenericTypeInfoCell, NonGenericTypeInfoCell};
use bevy_reflect_derive::{impl_from_reflect_value, impl_reflect_value}; use bevy_reflect_derive::{impl_from_reflect_value, impl_reflect_value};
use bevy_utils::{Duration, Instant}; use bevy_utils::{Duration, Instant};
use bevy_utils::{HashMap, HashSet}; use bevy_utils::{HashMap, HashSet};
#[cfg(any(unix, windows))]
use std::ffi::OsString;
use std::{ use std::{
any::Any, any::Any,
borrow::Cow, borrow::Cow,
@ -20,6 +22,7 @@ use std::{
NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize,
}, },
ops::{Range, RangeFrom, RangeFull, RangeInclusive, RangeTo, RangeToInclusive}, ops::{Range, RangeFrom, RangeFull, RangeInclusive, RangeTo, RangeToInclusive},
path::PathBuf,
}; };
impl_reflect_value!(bool(Debug, Hash, PartialEq, Serialize, Deserialize)); 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!(f32(Debug, PartialEq, Serialize, Deserialize));
impl_reflect_value!(f64(Debug, PartialEq, Serialize, Deserialize)); impl_reflect_value!(f64(Debug, PartialEq, Serialize, Deserialize));
impl_reflect_value!(String(Debug, Hash, 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<T: Clone + Reflect + 'static, E: Clone + Reflect + 'static>()); impl_reflect_value!(Result<T: Clone + Reflect + 'static, E: Clone + Reflect + 'static>());
impl_reflect_value!(HashSet<T: Hash + Eq + Clone + Send + Sync + 'static>()); impl_reflect_value!(HashSet<T: Hash + Eq + Clone + Send + Sync + 'static>());
impl_reflect_value!(Range<T: Clone + Send + Sync + 'static>()); impl_reflect_value!(Range<T: Clone + Send + Sync + 'static>());
@ -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!(NonZeroU8(Debug, Hash, PartialEq, Serialize, Deserialize));
impl_reflect_value!(NonZeroI8(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!(bool);
impl_from_reflect_value!(char); impl_from_reflect_value!(char);
impl_from_reflect_value!(u8); impl_from_reflect_value!(u8);