Skip to content

Commit b300b9d

Browse files
committed
wip
1 parent 301f618 commit b300b9d

File tree

3 files changed

+106
-234
lines changed

3 files changed

+106
-234
lines changed

crates/bevy_reflect/src/impls/std.rs

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use crate::{
1010
set_apply, set_partial_eq, set_try_apply,
1111
utility::{reflect_hasher, GenericTypeInfoCell, GenericTypePathCell, NonGenericTypeInfoCell},
1212
ApplyError, Array, ArrayInfo, ArrayIter, DynamicMap, DynamicTypePath, FromReflect, FromType,
13-
Generics, GetTypeRegistration, List, ListInfo, ListIter, Map, MapInfo, MapIter, MaybeTyped,
14-
OpaqueInfo, PartialReflect, Reflect, ReflectCloneError, ReflectDeserialize, ReflectFromPtr,
13+
Generics, GetTypeRegistration, List, ListInfo, ListIter, Map, MapInfo, MaybeTyped, OpaqueInfo,
14+
PartialReflect, Reflect, ReflectCloneError, ReflectDeserialize, ReflectFromPtr,
1515
ReflectFromReflect, ReflectKind, ReflectMut, ReflectOwned, ReflectRef, ReflectSerialize, Set,
1616
SetInfo, TypeInfo, TypeParamInfo, TypePath, TypeRegistration, TypeRegistry, Typed,
1717
};
@@ -736,27 +736,12 @@ macro_rules! impl_reflect_for_hashmap {
736736
.map(|value| value as &mut dyn PartialReflect)
737737
}
738738

739-
fn get_at(&self, index: usize) -> Option<(&dyn PartialReflect, &dyn PartialReflect)> {
740-
self.iter()
741-
.nth(index)
742-
.map(|(key, value)| (key as &dyn PartialReflect, value as &dyn PartialReflect))
743-
}
744-
745-
fn get_at_mut(
746-
&mut self,
747-
index: usize,
748-
) -> Option<(&dyn PartialReflect, &mut dyn PartialReflect)> {
749-
self.iter_mut().nth(index).map(|(key, value)| {
750-
(key as &dyn PartialReflect, value as &mut dyn PartialReflect)
751-
})
752-
}
753-
754739
fn len(&self) -> usize {
755740
Self::len(self)
756741
}
757742

758-
fn iter(&self) -> MapIter {
759-
MapIter::new(self)
743+
fn iter(&self) -> Box<dyn Iterator<Item = (&dyn PartialReflect, &dyn PartialReflect)> + '_> {
744+
Box::new(self.iter().map(|(k, v)| (k.as_partial_reflect(), v.as_partial_reflect())))
760745
}
761746

762747
fn drain(&mut self) -> Vec<(Box<dyn PartialReflect>, Box<dyn PartialReflect>)> {
@@ -770,6 +755,10 @@ macro_rules! impl_reflect_for_hashmap {
770755
.collect()
771756
}
772757

758+
fn retain(&mut self, f: &mut dyn FnMut(&dyn PartialReflect, &mut dyn PartialReflect) -> bool) {
759+
self.retain(move |key, value| f(key, value));
760+
}
761+
773762
fn to_dynamic_map(&self) -> DynamicMap {
774763
let mut dynamic_map = DynamicMap::default();
775764
dynamic_map.set_represented_type(self.get_represented_type_info());
@@ -1030,6 +1019,10 @@ macro_rules! impl_reflect_for_hashset {
10301019
.collect()
10311020
}
10321021

1022+
fn retain(&mut self, f: &mut dyn FnMut(&dyn PartialReflect) -> bool) {
1023+
self.retain(move |value| f(value));
1024+
}
1025+
10331026
fn insert_boxed(&mut self, value: Box<dyn PartialReflect>) -> bool {
10341027
let value = V::take_from_reflect(value).unwrap_or_else(|value| {
10351028
panic!(
@@ -1248,27 +1241,15 @@ where
12481241
.map(|value| value as &mut dyn PartialReflect)
12491242
}
12501243

1251-
fn get_at(&self, index: usize) -> Option<(&dyn PartialReflect, &dyn PartialReflect)> {
1252-
self.iter()
1253-
.nth(index)
1254-
.map(|(key, value)| (key as &dyn PartialReflect, value as &dyn PartialReflect))
1255-
}
1256-
1257-
fn get_at_mut(
1258-
&mut self,
1259-
index: usize,
1260-
) -> Option<(&dyn PartialReflect, &mut dyn PartialReflect)> {
1261-
self.iter_mut()
1262-
.nth(index)
1263-
.map(|(key, value)| (key as &dyn PartialReflect, value as &mut dyn PartialReflect))
1264-
}
1265-
12661244
fn len(&self) -> usize {
12671245
Self::len(self)
12681246
}
12691247

1270-
fn iter(&self) -> MapIter {
1271-
MapIter::new(self)
1248+
fn iter(&self) -> Box<dyn Iterator<Item = (&dyn PartialReflect, &dyn PartialReflect)> + '_> {
1249+
Box::new(
1250+
self.iter()
1251+
.map(|(k, v)| (k.as_partial_reflect(), v.as_partial_reflect())),
1252+
)
12721253
}
12731254

12741255
fn drain(&mut self) -> Vec<(Box<dyn PartialReflect>, Box<dyn PartialReflect>)> {
@@ -1285,6 +1266,10 @@ where
12851266
result
12861267
}
12871268

1269+
fn retain(&mut self, f: &mut dyn FnMut(&dyn PartialReflect, &mut dyn PartialReflect) -> bool) {
1270+
self.retain(move |key, value| f(key, value));
1271+
}
1272+
12881273
fn clone_dynamic(&self) -> DynamicMap {
12891274
let mut dynamic_map = DynamicMap::default();
12901275
dynamic_map.set_represented_type(self.get_represented_type_info());

0 commit comments

Comments
 (0)