Skip to content

Commit 30f4009

Browse files
committed
use impl_full_reflect in more places
1 parent 38f482b commit 30f4009

File tree

4 files changed

+28
-151
lines changed

4 files changed

+28
-151
lines changed

crates/bevy_reflect/src/impls/std.rs

Lines changed: 20 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ use crate::utility::{
33
reflect_hasher, GenericTypeInfoCell, GenericTypePathCell, NonGenericTypeInfoCell,
44
};
55
use crate::{
6-
self as bevy_reflect, impl_type_path, map_apply, map_partial_eq, map_try_apply, set_apply,
7-
set_partial_eq, set_try_apply, ApplyError, Array, ArrayInfo, ArrayIter, DynamicMap, DynamicSet,
8-
DynamicTypePath, FromReflect, FromType, GetTypeRegistration, List, ListInfo, ListIter, Map,
9-
MapInfo, MapIter, MaybeTyped, PartialReflect, Reflect, ReflectDeserialize, ReflectFromPtr,
10-
ReflectFromReflect, ReflectKind, ReflectMut, ReflectOwned, ReflectRef, ReflectSerialize, Set,
11-
SetInfo, TypeInfo, TypePath, TypeRegistration, TypeRegistry, Typed, ValueInfo,
6+
self as bevy_reflect, impl_type_path, map_apply, map_partial_eq, map_try_apply,
7+
reflect::impl_full_reflect, set_apply, set_partial_eq, set_try_apply, ApplyError, Array,
8+
ArrayInfo, ArrayIter, DynamicMap, DynamicSet, DynamicTypePath, FromReflect, FromType,
9+
GetTypeRegistration, List, ListInfo, ListIter, Map, MapInfo, MapIter, MaybeTyped,
10+
PartialReflect, Reflect, ReflectDeserialize, ReflectFromPtr, ReflectFromReflect, ReflectKind,
11+
ReflectMut, ReflectOwned, ReflectRef, ReflectSerialize, Set, SetInfo, TypeInfo, TypePath,
12+
TypeRegistration, TypeRegistry, Typed, ValueInfo,
1213
};
1314
use bevy_reflect_derive::{impl_reflect, impl_reflect_value};
1415
use std::fmt;
@@ -514,36 +515,7 @@ macro_rules! impl_reflect_for_veclike {
514515
}
515516
}
516517

517-
impl<T: FromReflect + MaybeTyped + TypePath + GetTypeRegistration> Reflect for $ty {
518-
fn into_any(self: Box<Self>) -> Box<dyn Any> {
519-
self
520-
}
521-
522-
fn as_any(&self) -> &dyn Any {
523-
self
524-
}
525-
526-
fn as_any_mut(&mut self) -> &mut dyn Any {
527-
self
528-
}
529-
530-
fn into_reflect(self: Box<Self>) -> Box<dyn Reflect> {
531-
self
532-
}
533-
534-
fn as_reflect(&self) -> &dyn Reflect {
535-
self
536-
}
537-
538-
fn as_reflect_mut(&mut self) -> &mut dyn Reflect {
539-
self
540-
}
541-
542-
fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>> {
543-
*self = value.take()?;
544-
Ok(())
545-
}
546-
}
518+
impl_full_reflect!(<T> for $ty where T: FromReflect + MaybeTyped + TypePath + GetTypeRegistration);
547519

548520
impl<T: FromReflect + MaybeTyped + TypePath + GetTypeRegistration> Typed for $ty {
549521
fn type_info() -> &'static TypeInfo {
@@ -1239,41 +1211,13 @@ where
12391211
map_try_apply(self, value)
12401212
}
12411213
}
1242-
impl<K, V> Reflect for ::std::collections::BTreeMap<K, V>
1243-
where
1244-
K: FromReflect + MaybeTyped + TypePath + GetTypeRegistration + Eq + Ord,
1245-
V: FromReflect + MaybeTyped + TypePath + GetTypeRegistration,
1246-
{
1247-
fn into_any(self: Box<Self>) -> Box<dyn Any> {
1248-
self
1249-
}
12501214

1251-
fn as_any(&self) -> &dyn Any {
1252-
self
1253-
}
1254-
1255-
fn as_any_mut(&mut self) -> &mut dyn Any {
1256-
self
1257-
}
1258-
1259-
#[inline]
1260-
fn into_reflect(self: Box<Self>) -> Box<dyn Reflect> {
1261-
self
1262-
}
1263-
1264-
fn as_reflect(&self) -> &dyn Reflect {
1265-
self
1266-
}
1267-
1268-
fn as_reflect_mut(&mut self) -> &mut dyn Reflect {
1269-
self
1270-
}
1271-
1272-
fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>> {
1273-
*self = value.take()?;
1274-
Ok(())
1275-
}
1276-
}
1215+
impl_full_reflect!(
1216+
<K, V> for ::std::collections::BTreeMap<K, V>
1217+
where
1218+
K: FromReflect + MaybeTyped + TypePath + GetTypeRegistration + Eq + Ord,
1219+
V: FromReflect + MaybeTyped + TypePath + GetTypeRegistration,
1220+
);
12771221

12781222
impl<K, V> Typed for ::std::collections::BTreeMap<K, V>
12791223
where
@@ -1644,36 +1588,7 @@ impl PartialReflect for Cow<'static, str> {
16441588
}
16451589
}
16461590

1647-
impl Reflect for Cow<'static, str> {
1648-
fn into_any(self: Box<Self>) -> Box<dyn Any> {
1649-
self
1650-
}
1651-
1652-
fn as_any(&self) -> &dyn Any {
1653-
self
1654-
}
1655-
1656-
fn as_any_mut(&mut self) -> &mut dyn Any {
1657-
self
1658-
}
1659-
1660-
fn into_reflect(self: Box<Self>) -> Box<dyn Reflect> {
1661-
self
1662-
}
1663-
1664-
fn as_reflect(&self) -> &dyn Reflect {
1665-
self
1666-
}
1667-
1668-
fn as_reflect_mut(&mut self) -> &mut dyn Reflect {
1669-
self
1670-
}
1671-
1672-
fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>> {
1673-
*self = value.take()?;
1674-
Ok(())
1675-
}
1676-
}
1591+
impl_full_reflect!(for Cow<'static, str>);
16771592

16781593
impl Typed for Cow<'static, str> {
16791594
fn type_info() -> &'static TypeInfo {
@@ -1846,38 +1761,11 @@ impl<T: FromReflect + MaybeTyped + Clone + TypePath + GetTypeRegistration> Parti
18461761
}
18471762
}
18481763

1849-
impl<T: FromReflect + Clone + MaybeTyped + TypePath + GetTypeRegistration> Reflect
1850-
for Cow<'static, [T]>
1851-
{
1852-
fn into_any(self: Box<Self>) -> Box<dyn Any> {
1853-
self
1854-
}
1855-
1856-
fn as_any(&self) -> &dyn Any {
1857-
self
1858-
}
1859-
1860-
fn as_any_mut(&mut self) -> &mut dyn Any {
1861-
self
1862-
}
1863-
1864-
fn into_reflect(self: Box<Self>) -> Box<dyn Reflect> {
1865-
self
1866-
}
1867-
1868-
fn as_reflect(&self) -> &dyn Reflect {
1869-
self
1870-
}
1871-
1872-
fn as_reflect_mut(&mut self) -> &mut dyn Reflect {
1873-
self
1874-
}
1875-
1876-
fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>> {
1877-
*self = value.take()?;
1878-
Ok(())
1879-
}
1880-
}
1764+
impl_full_reflect!(
1765+
<T> for Cow<'static, [T]>
1766+
where
1767+
T: FromReflect + Clone + MaybeTyped + TypePath + GetTypeRegistration,
1768+
);
18811769

18821770
impl<T: FromReflect + MaybeTyped + Clone + TypePath + GetTypeRegistration> Typed
18831771
for Cow<'static, [T]>

crates/bevy_reflect/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -523,9 +523,6 @@
523523
//! [`bevy_reflect_derive/documentation`]: bevy_reflect_derive
524524
//! [derive `Reflect`]: derive@crate::Reflect
525525
526-
#[macro_use]
527-
mod reflect;
528-
529526
mod array;
530527
mod fields;
531528
mod from_reflect;
@@ -534,6 +531,7 @@ pub mod func;
534531
mod list;
535532
mod map;
536533
mod path;
534+
mod reflect;
537535
mod set;
538536
mod struct_trait;
539537
mod tuple;

crates/bevy_reflect/src/reflect.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -568,18 +568,6 @@ impl Typed for dyn Reflect {
568568
}
569569
}
570570

571-
impl AsRef<dyn PartialReflect> for dyn Reflect {
572-
fn as_ref(&self) -> &dyn PartialReflect {
573-
self.as_partial_reflect()
574-
}
575-
}
576-
577-
impl AsMut<dyn PartialReflect> for dyn Reflect {
578-
fn as_mut(&mut self) -> &mut dyn PartialReflect {
579-
self.as_partial_reflect_mut()
580-
}
581-
}
582-
583571
// The following implementation never actually shadows the concrete `TypePath` implementation.
584572
// See this playground (https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=589064053f27bc100d90da89c6a860aa).
585573
impl TypePath for dyn Reflect {
@@ -592,8 +580,6 @@ impl TypePath for dyn Reflect {
592580
}
593581
}
594582

595-
#[macro_export]
596-
#[doc(hidden)]
597583
macro_rules! impl_full_reflect {
598584
($(<$($id:ident),* $(,)?>)? for $ty:ty $(where $($tt:tt)*)?) => {
599585
impl $(<$($id),*>)? $crate::Reflect for $ty $(where $($tt)*)? {
@@ -631,3 +617,5 @@ macro_rules! impl_full_reflect {
631617
}
632618
};
633619
}
620+
621+
pub(crate) use impl_full_reflect;

crates/bevy_state/src/reflect.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,11 @@ impl<S: FreelyMutableState + Reflect + TypePath> FromType<S> for ReflectFreelyMu
8484
fn from_type() -> Self {
8585
ReflectFreelyMutableState(ReflectFreelyMutableStateFns {
8686
set_next_state: |world, reflected_state, registry| {
87-
let new_state: S =
88-
from_reflect_with_fallback(reflected_state.as_ref(), world, registry);
87+
let new_state: S = from_reflect_with_fallback(
88+
reflected_state.as_partial_reflect(),
89+
world,
90+
registry,
91+
);
8992
if let Some(mut next_state) = world.get_resource_mut::<NextState<S>>() {
9093
next_state.set(new_state);
9194
}

0 commit comments

Comments
 (0)