Skip to main content

bevy_reflect/impls/std/
path.rs

1use crate::{
2    error::ReflectCloneError,
3    kind::{ReflectKind, ReflectMut, ReflectOwned, ReflectRef},
4    prelude::*,
5    reflect::ApplyError,
6    type_info::{OpaqueInfo, TypeInfo, Typed},
7    type_path::DynamicTypePath,
8    type_registry::{
9        FromType, GetTypeRegistration, ReflectDeserialize, ReflectFromPtr, ReflectSerialize,
10        TypeRegistration,
11    },
12    utility::{reflect_hasher, NonGenericTypeInfoCell},
13};
14use alloc::borrow::Cow;
15use bevy_platform::prelude::*;
16use bevy_reflect_derive::{impl_reflect_opaque, impl_type_path};
17use core::any::Any;
18use core::fmt;
19use core::hash::{Hash, Hasher};
20use std::path::Path;
21
22const _: () =
    {
        impl bevy_reflect::GetTypeRegistration for ::std::path::PathBuf where
            {
            fn get_type_registration() -> bevy_reflect::TypeRegistration {
                let mut registration =
                    bevy_reflect::TypeRegistration::of::<Self>();
                registration.insert::<bevy_reflect::ReflectFromPtr>(bevy_reflect::FromType::<Self>::from_type());
                registration.insert::<bevy_reflect::ReflectFromReflect>(bevy_reflect::FromType::<Self>::from_type());
                registration.register_type_data::<ReflectSerialize, Self>();
                registration.register_type_data::<ReflectDeserialize, Self>();
                registration.register_type_data::<ReflectDefault, Self>();
                registration
            }
        }
        #[allow(deprecated, reason =
        "derives on a deprecated type shouldn't be considered a usage")]
        impl bevy_reflect::TypePath for ::std::path::PathBuf where  {
            fn type_path() -> &'static str { "std::path::PathBuf" }
            fn short_type_path() -> &'static str { "PathBuf" }
            fn type_ident() -> ::core::option::Option<&'static str> {
                ::core::option::Option::Some("PathBuf")
            }
            fn crate_name() -> ::core::option::Option<&'static str> {
                ::core::option::Option::Some("std")
            }
            fn module_path() -> ::core::option::Option<&'static str> {
                ::core::option::Option::Some("std::path")
            }
        }
        impl bevy_reflect::Typed for ::std::path::PathBuf where  {
            #[inline]
            fn type_info() -> &'static bevy_reflect::TypeInfo {
                static CELL: bevy_reflect::utility::NonGenericTypeInfoCell =
                    bevy_reflect::utility::NonGenericTypeInfoCell::new();
                CELL.get_or_set(||
                        {
                            let info =
                                bevy_reflect::OpaqueInfo::new::<Self>().with_docs(::core::option::Option::None);
                            bevy_reflect::TypeInfo::Opaque(info)
                        })
            }
        }
        impl bevy_reflect::Reflect for ::std::path::PathBuf where  {
            #[inline]
            fn into_any(self:
                    bevy_reflect::__macro_exports::alloc_utils::Box<Self>)
                ->
                    bevy_reflect::__macro_exports::alloc_utils::Box<dyn ::core::any::Any> {
                self
            }
            #[inline]
            fn as_any(&self) -> &dyn ::core::any::Any { self }
            #[inline]
            fn as_any_mut(&mut self) -> &mut dyn ::core::any::Any { self }
            #[inline]
            fn into_reflect(self:
                    bevy_reflect::__macro_exports::alloc_utils::Box<Self>)
                ->
                    bevy_reflect::__macro_exports::alloc_utils::Box<dyn bevy_reflect::Reflect> {
                self
            }
            #[inline]
            fn as_reflect(&self) -> &dyn bevy_reflect::Reflect { self }
            #[inline]
            fn as_reflect_mut(&mut self) -> &mut dyn bevy_reflect::Reflect {
                self
            }
            #[inline]
            fn set(&mut self,
                value:
                    bevy_reflect::__macro_exports::alloc_utils::Box<dyn bevy_reflect::Reflect>)
                ->
                    ::core::result::Result<(),
                    bevy_reflect::__macro_exports::alloc_utils::Box<dyn bevy_reflect::Reflect>> {
                *self = <dyn bevy_reflect::Reflect>::take(value)?;
                ::core::result::Result::Ok(())
            }
        }
        impl bevy_reflect::func::args::GetOwnership for ::std::path::PathBuf
            where  {
            fn ownership() -> bevy_reflect::func::args::Ownership {
                bevy_reflect::func::args::Ownership::Owned
            }
        }
        impl bevy_reflect::func::args::FromArg for ::std::path::PathBuf where
            {
            type This<'from_arg> = ::std::path::PathBuf;
            fn from_arg(arg: bevy_reflect::func::args::Arg)
                ->
                    ::core::result::Result<Self::This<'_>,
                    bevy_reflect::func::args::ArgError> {
                arg.take_owned()
            }
        }
        impl bevy_reflect::func::IntoReturn for ::std::path::PathBuf where  {
            fn into_return<'into_return>(self)
                -> bevy_reflect::func::Return<'into_return> where
                Self: 'into_return {
                bevy_reflect::func::Return::Owned(bevy_reflect::__macro_exports::alloc_utils::Box::new(self))
            }
        }
        impl bevy_reflect::PartialReflect for ::std::path::PathBuf where  {
            #[inline]
            fn get_represented_type_info(&self)
                -> ::core::option::Option<&'static bevy_reflect::TypeInfo> {
                ::core::option::Option::Some(<Self as
                            bevy_reflect::Typed>::type_info())
            }
            #[inline]
            fn to_dynamic(&self)
                ->
                    bevy_reflect::__macro_exports::alloc_utils::Box<dyn bevy_reflect::PartialReflect> {
                bevy_reflect::__macro_exports::alloc_utils::Box::new(::core::clone::Clone::clone(self))
            }
            #[inline]
            fn try_apply(&mut self, value: &dyn bevy_reflect::PartialReflect)
                -> ::core::result::Result<(), bevy_reflect::ApplyError> {
                if let ::core::option::Option::Some(value) =
                        <dyn bevy_reflect::PartialReflect>::try_downcast_ref::<Self>(value)
                    {
                    *self = ::core::clone::Clone::clone(value);
                    return ::core::result::Result::Ok(());
                }
                ::core::result::Result::Err(bevy_reflect::ApplyError::MismatchedTypes {
                        from_type: ::core::convert::Into::into(bevy_reflect::DynamicTypePath::reflect_type_path(value)),
                        to_type: ::core::convert::Into::into(<Self as
                                    bevy_reflect::TypePath>::type_path()),
                    })
            }
            #[inline]
            fn reflect_kind(&self) -> bevy_reflect::ReflectKind {
                bevy_reflect::ReflectKind::Opaque
            }
            #[inline]
            fn reflect_ref(&self) -> bevy_reflect::ReflectRef {
                bevy_reflect::ReflectRef::Opaque(self)
            }
            #[inline]
            fn reflect_mut(&mut self) -> bevy_reflect::ReflectMut {
                bevy_reflect::ReflectMut::Opaque(self)
            }
            #[inline]
            fn reflect_owned(self:
                    bevy_reflect::__macro_exports::alloc_utils::Box<Self>)
                -> bevy_reflect::ReflectOwned {
                bevy_reflect::ReflectOwned::Opaque(self)
            }
            #[inline]
            fn try_into_reflect(self:
                    bevy_reflect::__macro_exports::alloc_utils::Box<Self>)
                ->
                    ::core::result::Result<bevy_reflect::__macro_exports::alloc_utils::Box<dyn bevy_reflect::Reflect>,
                    bevy_reflect::__macro_exports::alloc_utils::Box<dyn bevy_reflect::PartialReflect>> {
                ::core::result::Result::Ok(self)
            }
            #[inline]
            fn try_as_reflect(&self)
                -> ::core::option::Option<&dyn bevy_reflect::Reflect> {
                ::core::option::Option::Some(self)
            }
            #[inline]
            fn try_as_reflect_mut(&mut self)
                -> ::core::option::Option<&mut dyn bevy_reflect::Reflect> {
                ::core::option::Option::Some(self)
            }
            #[inline]
            fn into_partial_reflect(self:
                    bevy_reflect::__macro_exports::alloc_utils::Box<Self>)
                ->
                    bevy_reflect::__macro_exports::alloc_utils::Box<dyn bevy_reflect::PartialReflect> {
                self
            }
            #[inline]
            fn as_partial_reflect(&self)
                -> &dyn bevy_reflect::PartialReflect {
                self
            }
            #[inline]
            fn as_partial_reflect_mut(&mut self)
                -> &mut dyn bevy_reflect::PartialReflect {
                self
            }
            fn reflect_hash(&self) -> ::core::option::Option<u64> {
                use ::core::hash::{Hash, Hasher};
                let mut hasher = bevy_reflect::utility::reflect_hasher();
                Hash::hash(&::core::any::Any::type_id(self), &mut hasher);
                Hash::hash(self, &mut hasher);
                ::core::option::Option::Some(Hasher::finish(&hasher))
            }
            fn reflect_partial_eq(&self,
                value: &dyn bevy_reflect::PartialReflect)
                -> ::core::option::Option<bool> {
                let value =
                    <dyn bevy_reflect::PartialReflect>::try_downcast_ref::<Self>(value);
                if let ::core::option::Option::Some(value) = value {
                    ::core::option::Option::Some(::core::cmp::PartialEq::eq(self,
                            value))
                } else { ::core::option::Option::Some(false) }
            }
            fn reflect_partial_cmp(&self,
                value: &dyn bevy_reflect::PartialReflect)
                -> ::core::option::Option<::core::cmp::Ordering> {
                let value =
                    <dyn bevy_reflect::PartialReflect>::try_downcast_ref::<Self>(value);
                if let ::core::option::Option::Some(value) = value {
                    ::core::cmp::PartialOrd::partial_cmp(self, value)
                } else { ::core::option::Option::None }
            }
            fn debug(&self, f: &mut ::core::fmt::Formatter<'_>)
                -> ::core::fmt::Result {
                ::core::fmt::Debug::fmt(self, f)
            }
            #[inline]
            fn reflect_clone(&self)
                ->
                    ::core::result::Result<bevy_reflect::__macro_exports::alloc_utils::Box<dyn bevy_reflect::Reflect>,
                    bevy_reflect::ReflectCloneError> {
                ::core::result::Result::Ok(bevy_reflect::__macro_exports::alloc_utils::Box::new(::core::clone::Clone::clone(self)))
            }
        }
        impl bevy_reflect::FromReflect for ::std::path::PathBuf where  {
            fn from_reflect(reflect: &dyn bevy_reflect::PartialReflect)
                -> ::core::option::Option<Self> {
                ::core::option::Option::Some(::core::clone::Clone::clone(<dyn bevy_reflect::PartialReflect>::try_downcast_ref::<::std::path::PathBuf>(reflect)?))
            }
        }
    };impl_reflect_opaque!(::std::path::PathBuf(
23    Clone,
24    Debug,
25    Hash,
26    PartialEq,
27    PartialOrd,
28    Serialize,
29    Deserialize,
30    Default
31));
32
33impl PartialReflect for &'static Path {
34    fn get_represented_type_info(&self) -> Option<&'static TypeInfo> {
35        Some(<Self as Typed>::type_info())
36    }
37
38    #[inline]
39    fn into_partial_reflect(self: Box<Self>) -> Box<dyn PartialReflect> {
40        self
41    }
42
43    fn as_partial_reflect(&self) -> &dyn PartialReflect {
44        self
45    }
46
47    fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect {
48        self
49    }
50
51    fn try_into_reflect(self: Box<Self>) -> Result<Box<dyn Reflect>, Box<dyn PartialReflect>> {
52        Ok(self)
53    }
54
55    fn try_as_reflect(&self) -> Option<&dyn Reflect> {
56        Some(self)
57    }
58
59    fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect> {
60        Some(self)
61    }
62
63    fn reflect_kind(&self) -> ReflectKind {
64        ReflectKind::Opaque
65    }
66
67    fn reflect_ref(&self) -> ReflectRef<'_> {
68        ReflectRef::Opaque(self)
69    }
70
71    fn reflect_mut(&mut self) -> ReflectMut<'_> {
72        ReflectMut::Opaque(self)
73    }
74
75    fn reflect_owned(self: Box<Self>) -> ReflectOwned {
76        ReflectOwned::Opaque(self)
77    }
78
79    fn reflect_clone(&self) -> Result<Box<dyn Reflect>, ReflectCloneError> {
80        Ok(Box::new(*self))
81    }
82
83    fn reflect_hash(&self) -> Option<u64> {
84        let mut hasher = reflect_hasher();
85        Hash::hash(&Any::type_id(self), &mut hasher);
86        Hash::hash(self, &mut hasher);
87        Some(hasher.finish())
88    }
89
90    fn reflect_partial_eq(&self, value: &dyn PartialReflect) -> Option<bool> {
91        if let Some(value) = value.try_downcast_ref::<Self>() {
92            Some(PartialEq::eq(self, value))
93        } else {
94            Some(false)
95        }
96    }
97
98    fn reflect_partial_cmp(&self, value: &dyn PartialReflect) -> Option<core::cmp::Ordering> {
99        if let Some(value) = value.try_downcast_ref::<Self>() {
100            PartialOrd::partial_cmp(self, value)
101        } else {
102            None
103        }
104    }
105
106    fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError> {
107        if let Some(value) = value.try_downcast_ref::<Self>() {
108            self.clone_from(value);
109            Ok(())
110        } else {
111            Err(ApplyError::MismatchedTypes {
112                from_type: value.reflect_type_path().into(),
113                to_type: <Self as DynamicTypePath>::reflect_type_path(self).into(),
114            })
115        }
116    }
117}
118
119impl Reflect for &'static Path {
120    fn into_any(self: Box<Self>) -> Box<dyn Any> {
121        self
122    }
123
124    fn as_any(&self) -> &dyn Any {
125        self
126    }
127
128    fn as_any_mut(&mut self) -> &mut dyn Any {
129        self
130    }
131
132    fn into_reflect(self: Box<Self>) -> Box<dyn Reflect> {
133        self
134    }
135
136    fn as_reflect(&self) -> &dyn Reflect {
137        self
138    }
139
140    fn as_reflect_mut(&mut self) -> &mut dyn Reflect {
141        self
142    }
143
144    fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>> {
145        *self = value.take()?;
146        Ok(())
147    }
148}
149
150impl Typed for &'static Path {
151    fn type_info() -> &'static TypeInfo {
152        static CELL: NonGenericTypeInfoCell = NonGenericTypeInfoCell::new();
153        CELL.get_or_set(|| TypeInfo::Opaque(OpaqueInfo::new::<Self>()))
154    }
155}
156
157impl GetTypeRegistration for &'static Path {
158    fn get_type_registration() -> TypeRegistration {
159        let mut registration = TypeRegistration::of::<Self>();
160        registration.insert::<ReflectFromPtr>(FromType::<Self>::from_type());
161        registration.insert::<ReflectFromReflect>(FromType::<Self>::from_type());
162        registration
163    }
164}
165
166impl FromReflect for &'static Path {
167    fn from_reflect(reflect: &dyn PartialReflect) -> Option<Self> {
168        reflect.try_downcast_ref::<Self>().copied()
169    }
170}
171
172impl PartialReflect for Cow<'static, Path> {
173    fn get_represented_type_info(&self) -> Option<&'static TypeInfo> {
174        Some(<Self as Typed>::type_info())
175    }
176
177    #[inline]
178    fn into_partial_reflect(self: Box<Self>) -> Box<dyn PartialReflect> {
179        self
180    }
181
182    fn as_partial_reflect(&self) -> &dyn PartialReflect {
183        self
184    }
185
186    fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect {
187        self
188    }
189
190    fn try_into_reflect(self: Box<Self>) -> Result<Box<dyn Reflect>, Box<dyn PartialReflect>> {
191        Ok(self)
192    }
193
194    fn try_as_reflect(&self) -> Option<&dyn Reflect> {
195        Some(self)
196    }
197
198    fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect> {
199        Some(self)
200    }
201
202    fn reflect_kind(&self) -> ReflectKind {
203        ReflectKind::Opaque
204    }
205
206    fn reflect_ref(&self) -> ReflectRef<'_> {
207        ReflectRef::Opaque(self)
208    }
209
210    fn reflect_mut(&mut self) -> ReflectMut<'_> {
211        ReflectMut::Opaque(self)
212    }
213
214    fn reflect_owned(self: Box<Self>) -> ReflectOwned {
215        ReflectOwned::Opaque(self)
216    }
217
218    fn reflect_clone(&self) -> Result<Box<dyn Reflect>, ReflectCloneError> {
219        Ok(Box::new(self.clone()))
220    }
221
222    fn reflect_hash(&self) -> Option<u64> {
223        let mut hasher = reflect_hasher();
224        Hash::hash(&Any::type_id(self), &mut hasher);
225        Hash::hash(self, &mut hasher);
226        Some(hasher.finish())
227    }
228
229    fn reflect_partial_eq(&self, value: &dyn PartialReflect) -> Option<bool> {
230        if let Some(value) = value.try_downcast_ref::<Self>() {
231            Some(PartialEq::eq(self, value))
232        } else {
233            Some(false)
234        }
235    }
236
237    fn reflect_partial_cmp(&self, value: &dyn PartialReflect) -> Option<core::cmp::Ordering> {
238        if let Some(value) = value.try_downcast_ref::<Self>() {
239            PartialOrd::partial_cmp(self, value)
240        } else {
241            None
242        }
243    }
244
245    fn debug(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
246        fmt::Debug::fmt(&self, f)
247    }
248
249    fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError> {
250        if let Some(value) = value.try_downcast_ref::<Self>() {
251            self.clone_from(value);
252            Ok(())
253        } else {
254            Err(ApplyError::MismatchedTypes {
255                from_type: value.reflect_type_path().into(),
256                to_type: <Self as DynamicTypePath>::reflect_type_path(self).into(),
257            })
258        }
259    }
260}
261
262impl Reflect for Cow<'static, Path> {
263    fn into_any(self: Box<Self>) -> Box<dyn Any> {
264        self
265    }
266
267    fn as_any(&self) -> &dyn Any {
268        self
269    }
270
271    fn as_any_mut(&mut self) -> &mut dyn Any {
272        self
273    }
274
275    fn into_reflect(self: Box<Self>) -> Box<dyn Reflect> {
276        self
277    }
278
279    fn as_reflect(&self) -> &dyn Reflect {
280        self
281    }
282
283    fn as_reflect_mut(&mut self) -> &mut dyn Reflect {
284        self
285    }
286
287    fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>> {
288        *self = value.take()?;
289        Ok(())
290    }
291}
292
293impl Typed for Cow<'static, Path> {
294    fn type_info() -> &'static TypeInfo {
295        static CELL: NonGenericTypeInfoCell = NonGenericTypeInfoCell::new();
296        CELL.get_or_set(|| TypeInfo::Opaque(OpaqueInfo::new::<Self>()))
297    }
298}
299
300const _: () =
    {
        #[allow(deprecated, reason =
        "derives on a deprecated type shouldn't be considered a usage")]
        impl bevy_reflect::TypePath for ::std::path::Path where  {
            fn type_path() -> &'static str { "std::path::Path" }
            fn short_type_path() -> &'static str { "Path" }
            fn type_ident() -> ::core::option::Option<&'static str> {
                ::core::option::Option::Some("Path")
            }
            fn crate_name() -> ::core::option::Option<&'static str> {
                ::core::option::Option::Some("std")
            }
            fn module_path() -> ::core::option::Option<&'static str> {
                ::core::option::Option::Some("std::path")
            }
        }
    };impl_type_path!(::std::path::Path);
301
302impl FromReflect for Cow<'static, Path> {
303    fn from_reflect(reflect: &dyn PartialReflect) -> Option<Self> {
304        Some(reflect.try_downcast_ref::<Self>()?.clone())
305    }
306}
307
308impl GetTypeRegistration for Cow<'static, Path> {
309    fn get_type_registration() -> TypeRegistration {
310        let mut registration = TypeRegistration::of::<Self>();
311        registration.insert::<ReflectDeserialize>(FromType::<Self>::from_type());
312        registration.insert::<ReflectFromPtr>(FromType::<Self>::from_type());
313        registration.insert::<ReflectSerialize>(FromType::<Self>::from_type());
314        registration.insert::<ReflectFromReflect>(FromType::<Self>::from_type());
315        registration
316    }
317}
318
319#[cfg(feature = "functions")]
320impl crate::func::args::GetOwnership for Cow<'static, Path> {}
impl crate::func::args::FromArg for Cow<'static, Path> {
    type This<'from_arg> = Cow<'static, Path>;
    fn from_arg(arg: crate::func::args::Arg<'_>)
        -> Result<Self::This<'_>, crate::func::args::ArgError> {
        arg.take_owned()
    }
}
impl crate::func::IntoReturn for Cow<'static, Path> {
    fn into_return<'into_return>(self) -> crate::func::Return<'into_return>
        where Self: 'into_return {
        crate::func::Return::Owned(bevy_platform::prelude::Box::new(self))
    }
}crate::func::macros::impl_function_traits!(Cow<'static, Path>);