mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 12:43:34 +00:00
Fix reflection for PathBuf and OsString (#6776)
# Objective - `PathBuf` and `OsString` not reflected correctly. ## Solution - Add missing registrations. - Add FromReflect impls. - Always implement `Reflect` for `OsString` just skip `Serialize` and `Deserialize` for unsupported platforms. --- ## Changelog ## Fixed - Fix reflection for `PathBuf` and `OsString`.
This commit is contained in:
parent
ca74271d07
commit
523072902c
2 changed files with 11 additions and 5 deletions
|
@ -22,7 +22,9 @@ use bevy_ecs::entity::Entity;
|
||||||
use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
|
use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
|
||||||
use bevy_utils::{Duration, HashSet, Instant};
|
use bevy_utils::{Duration, HashSet, Instant};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
use std::ffi::OsString;
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
use bevy_ecs::schedule::IntoSystemDescriptor;
|
use bevy_ecs::schedule::IntoSystemDescriptor;
|
||||||
|
@ -62,6 +64,8 @@ fn register_rust_types(app: &mut App) {
|
||||||
.register_type_data::<Range<f32>, ReflectSerialize>()
|
.register_type_data::<Range<f32>, ReflectSerialize>()
|
||||||
.register_type_data::<Range<f32>, ReflectDeserialize>()
|
.register_type_data::<Range<f32>, ReflectDeserialize>()
|
||||||
.register_type::<String>()
|
.register_type::<String>()
|
||||||
|
.register_type::<PathBuf>()
|
||||||
|
.register_type::<OsString>()
|
||||||
.register_type::<HashSet<String>>()
|
.register_type::<HashSet<String>>()
|
||||||
.register_type::<Option<String>>()
|
.register_type::<Option<String>>()
|
||||||
.register_type::<Cow<'static, str>>()
|
.register_type::<Cow<'static, str>>()
|
||||||
|
|
|
@ -12,19 +12,17 @@ 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::path::Path;
|
|
||||||
use std::{
|
use std::{
|
||||||
any::Any,
|
any::Any,
|
||||||
borrow::Cow,
|
borrow::Cow,
|
||||||
|
ffi::OsString,
|
||||||
hash::{Hash, Hasher},
|
hash::{Hash, Hasher},
|
||||||
num::{
|
num::{
|
||||||
NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize, NonZeroU128,
|
NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize, NonZeroU128,
|
||||||
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,
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl_reflect_value!(bool(
|
impl_reflect_value!(bool(
|
||||||
|
@ -131,10 +129,12 @@ 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:
|
// `Serialize` and `Deserialize` only for platforms supported by serde:
|
||||||
// https://github.com/serde-rs/serde/blob/3ffb86fc70efd3d329519e2dddfa306cc04f167c/serde/src/de/impls.rs#L1732
|
// https://github.com/serde-rs/serde/blob/3ffb86fc70efd3d329519e2dddfa306cc04f167c/serde/src/de/impls.rs#L1732
|
||||||
#[cfg(any(unix, windows))]
|
#[cfg(any(unix, windows))]
|
||||||
impl_reflect_value!(OsString(Debug, Hash, PartialEq, Serialize, Deserialize));
|
impl_reflect_value!(OsString(Debug, Hash, PartialEq, Serialize, Deserialize));
|
||||||
|
#[cfg(not(any(unix, windows)))]
|
||||||
|
impl_reflect_value!(OsString(Debug, Hash, PartialEq));
|
||||||
|
|
||||||
impl_from_reflect_value!(bool);
|
impl_from_reflect_value!(bool);
|
||||||
impl_from_reflect_value!(char);
|
impl_from_reflect_value!(char);
|
||||||
|
@ -153,6 +153,8 @@ impl_from_reflect_value!(isize);
|
||||||
impl_from_reflect_value!(f32);
|
impl_from_reflect_value!(f32);
|
||||||
impl_from_reflect_value!(f64);
|
impl_from_reflect_value!(f64);
|
||||||
impl_from_reflect_value!(String);
|
impl_from_reflect_value!(String);
|
||||||
|
impl_from_reflect_value!(PathBuf);
|
||||||
|
impl_from_reflect_value!(OsString);
|
||||||
impl_from_reflect_value!(HashSet<T: Hash + Eq + Clone + Send + Sync + 'static>);
|
impl_from_reflect_value!(HashSet<T: Hash + Eq + Clone + Send + Sync + 'static>);
|
||||||
impl_from_reflect_value!(Range<T: Clone + Send + Sync + 'static>);
|
impl_from_reflect_value!(Range<T: Clone + Send + Sync + 'static>);
|
||||||
impl_from_reflect_value!(RangeInclusive<T: Clone + Send + Sync + 'static>);
|
impl_from_reflect_value!(RangeInclusive<T: Clone + Send + Sync + 'static>);
|
||||||
|
|
Loading…
Reference in a new issue