1use core::{
6 cmp::Ordering,
7 fmt::{self, Debug, Formatter},
8 hash::{BuildHasher, Hash, Hasher},
9 iter::FusedIterator,
10 marker::PhantomData,
11 ops::{
12 Bound, Deref, DerefMut, Index, IndexMut, Range, RangeBounds, RangeFrom, RangeFull,
13 RangeInclusive, RangeTo, RangeToInclusive,
14 },
15 ptr,
16};
17
18#[cfg(feature = "bevy_reflect")]
19use bevy_reflect::Reflect;
20use indexmap::map::{self, IndexMap, IntoValues, ValuesMut};
21
22use super::{Entity, EntityEquivalent, EntityHash, EntitySetIterator};
23
24use bevy_platform::prelude::Box;
25
26#[cfg_attr(feature = "bevy_reflect", derive(Reflect))]
28#[cfg_attr(feature = "serialize", derive(serde::Deserialize, serde::Serialize))]
29#[derive(Debug, Clone)]
30pub struct EntityIndexMap<V>(pub(crate) IndexMap<Entity, V, EntityHash>);
31
32impl<V> EntityIndexMap<V> {
33 pub const fn new() -> Self {
39 Self(IndexMap::with_hasher(EntityHash))
40 }
41
42 pub fn with_capacity(n: usize) -> Self {
48 Self(IndexMap::with_capacity_and_hasher(n, EntityHash))
49 }
50
51 pub fn into_inner(self) -> IndexMap<Entity, V, EntityHash> {
53 self.0
54 }
55
56 pub fn as_slice(&self) -> &Slice<V> {
60 unsafe { Slice::from_slice_unchecked(self.0.as_slice()) }
62 }
63
64 pub fn as_mut_slice(&mut self) -> &mut Slice<V> {
68 unsafe { Slice::from_slice_unchecked_mut(self.0.as_mut_slice()) }
70 }
71
72 pub fn into_boxed_slice(self) -> Box<Slice<V>> {
76 unsafe { Slice::from_boxed_slice_unchecked(self.0.into_boxed_slice()) }
78 }
79
80 pub fn get_range<R: RangeBounds<usize>>(&self, range: R) -> Option<&Slice<V>> {
84 self.0.get_range(range).map(|slice|
85 unsafe { Slice::from_slice_unchecked(slice) })
87 }
88
89 pub fn get_range_mut<R: RangeBounds<usize>>(&mut self, range: R) -> Option<&mut Slice<V>> {
93 self.0.get_range_mut(range).map(|slice|
94 unsafe { Slice::from_slice_unchecked_mut(slice) })
96 }
97
98 pub fn iter(&self) -> Iter<'_, V> {
102 Iter(self.0.iter(), PhantomData)
103 }
104
105 pub fn iter_mut(&mut self) -> IterMut<'_, V> {
109 IterMut(self.0.iter_mut(), PhantomData)
110 }
111
112 pub fn drain<R: RangeBounds<usize>>(&mut self, range: R) -> Drain<'_, V> {
117 Drain(self.0.drain(range), PhantomData)
118 }
119
120 pub fn keys(&self) -> Keys<'_, V> {
124 Keys(self.0.keys(), PhantomData)
125 }
126
127 pub fn into_keys(self) -> IntoKeys<V> {
131 IntoKeys(self.0.into_keys(), PhantomData)
132 }
133}
134
135impl<V> Default for EntityIndexMap<V> {
136 fn default() -> Self {
137 Self(Default::default())
138 }
139}
140
141impl<V> Deref for EntityIndexMap<V> {
142 type Target = IndexMap<Entity, V, EntityHash>;
143
144 fn deref(&self) -> &Self::Target {
145 &self.0
146 }
147}
148
149impl<V> DerefMut for EntityIndexMap<V> {
150 fn deref_mut(&mut self) -> &mut Self::Target {
151 &mut self.0
152 }
153}
154
155impl<'a, V: Copy> Extend<(&'a Entity, &'a V)> for EntityIndexMap<V> {
156 fn extend<T: IntoIterator<Item = (&'a Entity, &'a V)>>(&mut self, iter: T) {
157 self.0.extend(iter);
158 }
159}
160
161impl<V> Extend<(Entity, V)> for EntityIndexMap<V> {
162 fn extend<T: IntoIterator<Item = (Entity, V)>>(&mut self, iter: T) {
163 self.0.extend(iter);
164 }
165}
166
167impl<V, const N: usize> From<[(Entity, V); N]> for EntityIndexMap<V> {
168 fn from(value: [(Entity, V); N]) -> Self {
169 Self(IndexMap::from_iter(value))
170 }
171}
172
173impl<V> FromIterator<(Entity, V)> for EntityIndexMap<V> {
174 fn from_iter<I: IntoIterator<Item = (Entity, V)>>(iterable: I) -> Self {
175 Self(IndexMap::from_iter(iterable))
176 }
177}
178
179impl<V, Q: EntityEquivalent + ?Sized> Index<&Q> for EntityIndexMap<V> {
180 type Output = V;
181 fn index(&self, key: &Q) -> &V {
182 self.0.index(&key.entity())
183 }
184}
185
186impl<V> Index<(Bound<usize>, Bound<usize>)> for EntityIndexMap<V> {
187 type Output = Slice<V>;
188 fn index(&self, key: (Bound<usize>, Bound<usize>)) -> &Self::Output {
189 unsafe { Slice::from_slice_unchecked(self.0.index(key)) }
191 }
192}
193
194impl<V> Index<Range<usize>> for EntityIndexMap<V> {
195 type Output = Slice<V>;
196 fn index(&self, key: Range<usize>) -> &Self::Output {
197 unsafe { Slice::from_slice_unchecked(self.0.index(key)) }
199 }
200}
201
202impl<V> Index<RangeFrom<usize>> for EntityIndexMap<V> {
203 type Output = Slice<V>;
204 fn index(&self, key: RangeFrom<usize>) -> &Self::Output {
205 unsafe { Slice::from_slice_unchecked(self.0.index(key)) }
207 }
208}
209
210impl<V> Index<RangeFull> for EntityIndexMap<V> {
211 type Output = Slice<V>;
212 fn index(&self, key: RangeFull) -> &Self::Output {
213 unsafe { Slice::from_slice_unchecked(self.0.index(key)) }
215 }
216}
217
218impl<V> Index<RangeInclusive<usize>> for EntityIndexMap<V> {
219 type Output = Slice<V>;
220 fn index(&self, key: RangeInclusive<usize>) -> &Self::Output {
221 unsafe { Slice::from_slice_unchecked(self.0.index(key)) }
223 }
224}
225
226impl<V> Index<RangeTo<usize>> for EntityIndexMap<V> {
227 type Output = Slice<V>;
228 fn index(&self, key: RangeTo<usize>) -> &Self::Output {
229 unsafe { Slice::from_slice_unchecked(self.0.index(key)) }
231 }
232}
233
234impl<V> Index<RangeToInclusive<usize>> for EntityIndexMap<V> {
235 type Output = Slice<V>;
236 fn index(&self, key: RangeToInclusive<usize>) -> &Self::Output {
237 unsafe { Slice::from_slice_unchecked(self.0.index(key)) }
239 }
240}
241
242impl<V> Index<usize> for EntityIndexMap<V> {
243 type Output = V;
244 fn index(&self, key: usize) -> &V {
245 self.0.index(key)
246 }
247}
248
249impl<V, Q: EntityEquivalent + ?Sized> IndexMut<&Q> for EntityIndexMap<V> {
250 fn index_mut(&mut self, key: &Q) -> &mut V {
251 self.0.index_mut(&key.entity())
252 }
253}
254
255impl<V> IndexMut<(Bound<usize>, Bound<usize>)> for EntityIndexMap<V> {
256 fn index_mut(&mut self, key: (Bound<usize>, Bound<usize>)) -> &mut Self::Output {
257 unsafe { Slice::from_slice_unchecked_mut(self.0.index_mut(key)) }
259 }
260}
261
262impl<V> IndexMut<Range<usize>> for EntityIndexMap<V> {
263 fn index_mut(&mut self, key: Range<usize>) -> &mut Self::Output {
264 unsafe { Slice::from_slice_unchecked_mut(self.0.index_mut(key)) }
266 }
267}
268
269impl<V> IndexMut<RangeFrom<usize>> for EntityIndexMap<V> {
270 fn index_mut(&mut self, key: RangeFrom<usize>) -> &mut Self::Output {
271 unsafe { Slice::from_slice_unchecked_mut(self.0.index_mut(key)) }
273 }
274}
275
276impl<V> IndexMut<RangeFull> for EntityIndexMap<V> {
277 fn index_mut(&mut self, key: RangeFull) -> &mut Self::Output {
278 unsafe { Slice::from_slice_unchecked_mut(self.0.index_mut(key)) }
280 }
281}
282
283impl<V> IndexMut<RangeInclusive<usize>> for EntityIndexMap<V> {
284 fn index_mut(&mut self, key: RangeInclusive<usize>) -> &mut Self::Output {
285 unsafe { Slice::from_slice_unchecked_mut(self.0.index_mut(key)) }
287 }
288}
289
290impl<V> IndexMut<RangeTo<usize>> for EntityIndexMap<V> {
291 fn index_mut(&mut self, key: RangeTo<usize>) -> &mut Self::Output {
292 unsafe { Slice::from_slice_unchecked_mut(self.0.index_mut(key)) }
294 }
295}
296
297impl<V> IndexMut<RangeToInclusive<usize>> for EntityIndexMap<V> {
298 fn index_mut(&mut self, key: RangeToInclusive<usize>) -> &mut Self::Output {
299 unsafe { Slice::from_slice_unchecked_mut(self.0.index_mut(key)) }
301 }
302}
303
304impl<V> IndexMut<usize> for EntityIndexMap<V> {
305 fn index_mut(&mut self, key: usize) -> &mut V {
306 self.0.index_mut(key)
307 }
308}
309
310impl<'a, V> IntoIterator for &'a EntityIndexMap<V> {
311 type Item = (&'a Entity, &'a V);
312 type IntoIter = Iter<'a, V>;
313
314 fn into_iter(self) -> Self::IntoIter {
315 Iter(self.0.iter(), PhantomData)
316 }
317}
318
319impl<'a, V> IntoIterator for &'a mut EntityIndexMap<V> {
320 type Item = (&'a Entity, &'a mut V);
321 type IntoIter = IterMut<'a, V>;
322
323 fn into_iter(self) -> Self::IntoIter {
324 IterMut(self.0.iter_mut(), PhantomData)
325 }
326}
327
328impl<V> IntoIterator for EntityIndexMap<V> {
329 type Item = (Entity, V);
330 type IntoIter = IntoIter<V>;
331
332 fn into_iter(self) -> Self::IntoIter {
333 IntoIter(self.0.into_iter(), PhantomData)
334 }
335}
336
337impl<V1, V2, S2> PartialEq<IndexMap<Entity, V2, S2>> for EntityIndexMap<V1>
338where
339 V1: PartialEq<V2>,
340 S2: BuildHasher,
341{
342 fn eq(&self, other: &IndexMap<Entity, V2, S2>) -> bool {
343 self.0.eq(other)
344 }
345}
346
347impl<V1, V2> PartialEq<EntityIndexMap<V2>> for EntityIndexMap<V1>
348where
349 V1: PartialEq<V2>,
350{
351 fn eq(&self, other: &EntityIndexMap<V2>) -> bool {
352 self.0.eq(other)
353 }
354}
355
356impl<V: Eq> Eq for EntityIndexMap<V> {}
357
358#[repr(transparent)]
363pub struct Slice<V, S = EntityHash>(PhantomData<S>, map::Slice<Entity, V>);
364
365impl<V> Slice<V> {
366 pub const fn new<'a>() -> &'a Self {
370 unsafe { Self::from_slice_unchecked(map::Slice::new()) }
372 }
373
374 pub fn new_mut<'a>() -> &'a mut Self {
378 unsafe { Self::from_slice_unchecked_mut(map::Slice::new_mut()) }
380 }
381
382 pub const unsafe fn from_slice_unchecked(slice: &map::Slice<Entity, V>) -> &Self {
390 unsafe { &*(ptr::from_ref(slice) as *const Self) }
392 }
393
394 pub const unsafe fn from_slice_unchecked_mut(slice: &mut map::Slice<Entity, V>) -> &mut Self {
402 unsafe { &mut *(ptr::from_mut(slice) as *mut Self) }
404 }
405
406 pub const fn as_inner(&self) -> &map::Slice<Entity, V> {
408 &self.1
409 }
410
411 pub unsafe fn from_boxed_slice_unchecked(slice: Box<map::Slice<Entity, V>>) -> Box<Self> {
419 unsafe { Box::from_raw(Box::into_raw(slice) as *mut Self) }
421 }
422
423 #[expect(
425 clippy::borrowed_box,
426 reason = "We wish to access the Box API of the inner type, without consuming it."
427 )]
428 pub fn as_boxed_inner(self: &Box<Self>) -> &Box<map::Slice<Entity, V>> {
429 unsafe { &*(ptr::from_ref(self).cast::<Box<map::Slice<Entity, V>>>()) }
431 }
432
433 pub fn into_boxed_inner(self: Box<Self>) -> Box<map::Slice<Entity, V>> {
435 unsafe { Box::from_raw(Box::into_raw(self) as *mut map::Slice<Entity, V>) }
437 }
438
439 pub fn get_index_mut(&mut self, index: usize) -> Option<(&Entity, &mut V)> {
443 self.1.get_index_mut(index)
444 }
445
446 pub fn get_range<R: RangeBounds<usize>>(&self, range: R) -> Option<&Self> {
450 self.1.get_range(range).map(|slice|
451 unsafe { Self::from_slice_unchecked(slice) })
453 }
454
455 pub fn get_range_mut<R: RangeBounds<usize>>(&mut self, range: R) -> Option<&mut Self> {
459 self.1.get_range_mut(range).map(|slice|
460 unsafe { Self::from_slice_unchecked_mut(slice) })
462 }
463
464 pub fn first_mut(&mut self) -> Option<(&Entity, &mut V)> {
468 self.1.first_mut()
469 }
470
471 pub fn last_mut(&mut self) -> Option<(&Entity, &mut V)> {
475 self.1.last_mut()
476 }
477
478 pub fn split_at(&self, index: usize) -> (&Self, &Self) {
482 let (slice_1, slice_2) = self.1.split_at(index);
483 unsafe {
485 (
486 Self::from_slice_unchecked(slice_1),
487 Self::from_slice_unchecked(slice_2),
488 )
489 }
490 }
491
492 pub fn split_at_mut(&mut self, index: usize) -> (&mut Self, &mut Self) {
496 let (slice_1, slice_2) = self.1.split_at_mut(index);
497 unsafe {
499 (
500 Self::from_slice_unchecked_mut(slice_1),
501 Self::from_slice_unchecked_mut(slice_2),
502 )
503 }
504 }
505
506 pub fn split_first(&self) -> Option<((&Entity, &V), &Self)> {
511 self.1.split_first().map(|(first, rest)| {
512 (
513 first,
514 unsafe { Self::from_slice_unchecked(rest) },
516 )
517 })
518 }
519
520 pub fn split_first_mut(&mut self) -> Option<((&Entity, &mut V), &mut Self)> {
525 self.1.split_first_mut().map(|(first, rest)| {
526 (
527 first,
528 unsafe { Self::from_slice_unchecked_mut(rest) },
530 )
531 })
532 }
533
534 pub fn split_last(&self) -> Option<((&Entity, &V), &Self)> {
539 self.1.split_last().map(|(last, rest)| {
540 (
541 last,
542 unsafe { Self::from_slice_unchecked(rest) },
544 )
545 })
546 }
547
548 pub fn split_last_mut(&mut self) -> Option<((&Entity, &mut V), &mut Self)> {
553 self.1.split_last_mut().map(|(last, rest)| {
554 (
555 last,
556 unsafe { Self::from_slice_unchecked_mut(rest) },
558 )
559 })
560 }
561
562 pub fn iter(&self) -> Iter<'_, V> {
566 Iter(self.1.iter(), PhantomData)
567 }
568
569 pub fn iter_mut(&mut self) -> IterMut<'_, V> {
573 IterMut(self.1.iter_mut(), PhantomData)
574 }
575
576 pub fn keys(&self) -> Keys<'_, V> {
580 Keys(self.1.keys(), PhantomData)
581 }
582
583 pub fn into_keys(self: Box<Self>) -> IntoKeys<V> {
587 IntoKeys(self.into_boxed_inner().into_keys(), PhantomData)
588 }
589
590 pub fn values_mut(&mut self) -> ValuesMut<'_, Entity, V> {
594 self.1.values_mut()
595 }
596
597 pub fn into_values(self: Box<Self>) -> IntoValues<Entity, V> {
601 self.into_boxed_inner().into_values()
602 }
603}
604
605impl<V> Deref for Slice<V> {
606 type Target = map::Slice<Entity, V>;
607
608 fn deref(&self) -> &Self::Target {
609 &self.1
610 }
611}
612
613impl<V: Debug> Debug for Slice<V> {
614 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
615 f.debug_tuple("Slice")
616 .field(&self.0)
617 .field(&&self.1)
618 .finish()
619 }
620}
621
622impl<V: Clone> Clone for Box<Slice<V>> {
623 fn clone(&self) -> Self {
624 unsafe { Slice::from_boxed_slice_unchecked(self.as_boxed_inner().clone()) }
626 }
627}
628
629impl<V> Default for &Slice<V> {
630 fn default() -> Self {
631 unsafe { Slice::from_slice_unchecked(<&map::Slice<Entity, V>>::default()) }
633 }
634}
635
636impl<V> Default for &mut Slice<V> {
637 fn default() -> Self {
638 unsafe { Slice::from_slice_unchecked_mut(<&mut map::Slice<Entity, V>>::default()) }
640 }
641}
642
643impl<V> Default for Box<Slice<V>> {
644 fn default() -> Self {
645 unsafe { Slice::from_boxed_slice_unchecked(<Box<map::Slice<Entity, V>>>::default()) }
647 }
648}
649
650impl<V: Copy> From<&Slice<V>> for Box<Slice<V>> {
651 fn from(value: &Slice<V>) -> Self {
652 unsafe { Slice::from_boxed_slice_unchecked(value.1.into()) }
654 }
655}
656
657impl<V: Hash> Hash for Slice<V> {
658 fn hash<H: Hasher>(&self, state: &mut H) {
659 self.1.hash(state);
660 }
661}
662
663impl<'a, V> IntoIterator for &'a Slice<V> {
664 type Item = (&'a Entity, &'a V);
665 type IntoIter = Iter<'a, V>;
666
667 fn into_iter(self) -> Self::IntoIter {
668 Iter(self.1.iter(), PhantomData)
669 }
670}
671
672impl<'a, V> IntoIterator for &'a mut Slice<V> {
673 type Item = (&'a Entity, &'a mut V);
674 type IntoIter = IterMut<'a, V>;
675
676 fn into_iter(self) -> Self::IntoIter {
677 IterMut(self.1.iter_mut(), PhantomData)
678 }
679}
680
681impl<V> IntoIterator for Box<Slice<V>> {
682 type Item = (Entity, V);
683 type IntoIter = IntoIter<V>;
684
685 fn into_iter(self) -> Self::IntoIter {
686 IntoIter(self.into_boxed_inner().into_iter(), PhantomData)
687 }
688}
689
690impl<V: PartialOrd> PartialOrd for Slice<V> {
691 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
692 self.1.partial_cmp(&other.1)
693 }
694}
695
696impl<V: Ord> Ord for Slice<V> {
697 fn cmp(&self, other: &Self) -> Ordering {
698 self.1.cmp(other)
699 }
700}
701
702impl<V: PartialEq> PartialEq for Slice<V> {
703 fn eq(&self, other: &Self) -> bool {
704 self.1 == other.1
705 }
706}
707
708impl<V: Eq> Eq for Slice<V> {}
709
710impl<V> Index<(Bound<usize>, Bound<usize>)> for Slice<V> {
711 type Output = Self;
712 fn index(&self, key: (Bound<usize>, Bound<usize>)) -> &Self {
713 unsafe { Self::from_slice_unchecked(self.1.index(key)) }
715 }
716}
717
718impl<V> Index<Range<usize>> for Slice<V> {
719 type Output = Self;
720 fn index(&self, key: Range<usize>) -> &Self {
721 unsafe { Self::from_slice_unchecked(self.1.index(key)) }
723 }
724}
725
726impl<V> Index<RangeFrom<usize>> for Slice<V> {
727 type Output = Self;
728 fn index(&self, key: RangeFrom<usize>) -> &Self {
729 unsafe { Self::from_slice_unchecked(self.1.index(key)) }
731 }
732}
733
734impl<V> Index<RangeFull> for Slice<V> {
735 type Output = Self;
736 fn index(&self, key: RangeFull) -> &Self {
737 unsafe { Self::from_slice_unchecked(self.1.index(key)) }
739 }
740}
741
742impl<V> Index<RangeInclusive<usize>> for Slice<V> {
743 type Output = Self;
744 fn index(&self, key: RangeInclusive<usize>) -> &Self {
745 unsafe { Self::from_slice_unchecked(self.1.index(key)) }
747 }
748}
749
750impl<V> Index<RangeTo<usize>> for Slice<V> {
751 type Output = Self;
752 fn index(&self, key: RangeTo<usize>) -> &Self {
753 unsafe { Self::from_slice_unchecked(self.1.index(key)) }
755 }
756}
757
758impl<V> Index<RangeToInclusive<usize>> for Slice<V> {
759 type Output = Self;
760 fn index(&self, key: RangeToInclusive<usize>) -> &Self {
761 unsafe { Self::from_slice_unchecked(self.1.index(key)) }
763 }
764}
765
766impl<V> Index<usize> for Slice<V> {
767 type Output = V;
768 fn index(&self, key: usize) -> &V {
769 self.1.index(key)
770 }
771}
772
773impl<V> IndexMut<(Bound<usize>, Bound<usize>)> for Slice<V> {
774 fn index_mut(&mut self, key: (Bound<usize>, Bound<usize>)) -> &mut Self {
775 unsafe { Self::from_slice_unchecked_mut(self.1.index_mut(key)) }
777 }
778}
779
780impl<V> IndexMut<Range<usize>> for Slice<V> {
781 fn index_mut(&mut self, key: Range<usize>) -> &mut Self {
782 unsafe { Self::from_slice_unchecked_mut(self.1.index_mut(key)) }
784 }
785}
786
787impl<V> IndexMut<RangeFrom<usize>> for Slice<V> {
788 fn index_mut(&mut self, key: RangeFrom<usize>) -> &mut Self {
789 unsafe { Self::from_slice_unchecked_mut(self.1.index_mut(key)) }
791 }
792}
793
794impl<V> IndexMut<RangeFull> for Slice<V> {
795 fn index_mut(&mut self, key: RangeFull) -> &mut Self {
796 unsafe { Self::from_slice_unchecked_mut(self.1.index_mut(key)) }
798 }
799}
800
801impl<V> IndexMut<RangeInclusive<usize>> for Slice<V> {
802 fn index_mut(&mut self, key: RangeInclusive<usize>) -> &mut Self {
803 unsafe { Self::from_slice_unchecked_mut(self.1.index_mut(key)) }
805 }
806}
807
808impl<V> IndexMut<RangeTo<usize>> for Slice<V> {
809 fn index_mut(&mut self, key: RangeTo<usize>) -> &mut Self {
810 unsafe { Self::from_slice_unchecked_mut(self.1.index_mut(key)) }
812 }
813}
814
815impl<V> IndexMut<RangeToInclusive<usize>> for Slice<V> {
816 fn index_mut(&mut self, key: RangeToInclusive<usize>) -> &mut Self {
817 unsafe { Self::from_slice_unchecked_mut(self.1.index_mut(key)) }
819 }
820}
821
822impl<V> IndexMut<usize> for Slice<V> {
823 fn index_mut(&mut self, key: usize) -> &mut V {
824 self.1.index_mut(key)
825 }
826}
827
828pub struct Iter<'a, V, S = EntityHash>(map::Iter<'a, Entity, V>, PhantomData<S>);
833
834impl<'a, V> Iter<'a, V> {
835 pub fn into_inner(self) -> map::Iter<'a, Entity, V> {
837 self.0
838 }
839
840 pub fn as_slice(&self) -> &Slice<V> {
844 unsafe { Slice::from_slice_unchecked(self.0.as_slice()) }
846 }
847}
848
849impl<'a, V> Deref for Iter<'a, V> {
850 type Target = map::Iter<'a, Entity, V>;
851
852 fn deref(&self) -> &Self::Target {
853 &self.0
854 }
855}
856
857impl<'a, V> Iterator for Iter<'a, V> {
858 type Item = (&'a Entity, &'a V);
859
860 fn next(&mut self) -> Option<Self::Item> {
861 self.0.next()
862 }
863}
864
865impl<V> DoubleEndedIterator for Iter<'_, V> {
866 fn next_back(&mut self) -> Option<Self::Item> {
867 self.0.next_back()
868 }
869}
870
871impl<V> ExactSizeIterator for Iter<'_, V> {}
872
873impl<V> FusedIterator for Iter<'_, V> {}
874
875impl<V> Clone for Iter<'_, V> {
876 fn clone(&self) -> Self {
877 Self(self.0.clone(), PhantomData)
878 }
879}
880
881impl<V: Debug> Debug for Iter<'_, V> {
882 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
883 f.debug_tuple("Iter").field(&self.0).field(&self.1).finish()
884 }
885}
886
887impl<V> Default for Iter<'_, V> {
888 fn default() -> Self {
889 Self(Default::default(), PhantomData)
890 }
891}
892
893pub struct IterMut<'a, V, S = EntityHash>(map::IterMut<'a, Entity, V>, PhantomData<S>);
898
899impl<'a, V> IterMut<'a, V> {
900 pub fn into_inner(self) -> map::IterMut<'a, Entity, V> {
902 self.0
903 }
904
905 pub fn as_slice(&self) -> &Slice<V> {
909 unsafe { Slice::from_slice_unchecked(self.0.as_slice()) }
911 }
912
913 pub fn into_slice(self) -> &'a mut Slice<V> {
917 unsafe { Slice::from_slice_unchecked_mut(self.0.into_slice()) }
919 }
920}
921
922impl<'a, V> Deref for IterMut<'a, V> {
923 type Target = map::IterMut<'a, Entity, V>;
924
925 fn deref(&self) -> &Self::Target {
926 &self.0
927 }
928}
929
930impl<'a, V> Iterator for IterMut<'a, V> {
931 type Item = (&'a Entity, &'a mut V);
932
933 fn next(&mut self) -> Option<Self::Item> {
934 self.0.next()
935 }
936}
937
938impl<V> DoubleEndedIterator for IterMut<'_, V> {
939 fn next_back(&mut self) -> Option<Self::Item> {
940 self.0.next_back()
941 }
942}
943
944impl<V> ExactSizeIterator for IterMut<'_, V> {}
945
946impl<V> FusedIterator for IterMut<'_, V> {}
947
948impl<V: Debug> Debug for IterMut<'_, V> {
949 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
950 f.debug_tuple("IterMut")
951 .field(&self.0)
952 .field(&self.1)
953 .finish()
954 }
955}
956
957impl<V> Default for IterMut<'_, V> {
958 fn default() -> Self {
959 Self(Default::default(), PhantomData)
960 }
961}
962
963pub struct IntoIter<V, S = EntityHash>(map::IntoIter<Entity, V>, PhantomData<S>);
968
969impl<V> IntoIter<V> {
970 pub fn into_inner(self) -> map::IntoIter<Entity, V> {
972 self.0
973 }
974
975 pub fn as_slice(&self) -> &Slice<V> {
979 unsafe { Slice::from_slice_unchecked(self.0.as_slice()) }
981 }
982
983 pub fn as_mut_slice(&mut self) -> &mut Slice<V> {
987 unsafe { Slice::from_slice_unchecked_mut(self.0.as_mut_slice()) }
989 }
990}
991
992impl<V> Deref for IntoIter<V> {
993 type Target = map::IntoIter<Entity, V>;
994
995 fn deref(&self) -> &Self::Target {
996 &self.0
997 }
998}
999
1000impl<V> Iterator for IntoIter<V> {
1001 type Item = (Entity, V);
1002
1003 fn next(&mut self) -> Option<Self::Item> {
1004 self.0.next()
1005 }
1006}
1007
1008impl<V> DoubleEndedIterator for IntoIter<V> {
1009 fn next_back(&mut self) -> Option<Self::Item> {
1010 self.0.next_back()
1011 }
1012}
1013
1014impl<V> ExactSizeIterator for IntoIter<V> {}
1015
1016impl<V> FusedIterator for IntoIter<V> {}
1017
1018impl<V: Clone> Clone for IntoIter<V> {
1019 fn clone(&self) -> Self {
1020 Self(self.0.clone(), PhantomData)
1021 }
1022}
1023
1024impl<V: Debug> Debug for IntoIter<V> {
1025 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
1026 f.debug_tuple("IntoIter")
1027 .field(&self.0)
1028 .field(&self.1)
1029 .finish()
1030 }
1031}
1032
1033impl<V> Default for IntoIter<V> {
1034 fn default() -> Self {
1035 Self(Default::default(), PhantomData)
1036 }
1037}
1038
1039pub struct Drain<'a, V, S = EntityHash>(map::Drain<'a, Entity, V>, PhantomData<S>);
1044
1045impl<'a, V> Drain<'a, V> {
1046 pub fn into_inner(self) -> map::Drain<'a, Entity, V> {
1048 self.0
1049 }
1050
1051 pub fn as_slice(&self) -> &Slice<V> {
1055 unsafe { Slice::from_slice_unchecked(self.0.as_slice()) }
1057 }
1058}
1059
1060impl<'a, V> Deref for Drain<'a, V> {
1061 type Target = map::Drain<'a, Entity, V>;
1062
1063 fn deref(&self) -> &Self::Target {
1064 &self.0
1065 }
1066}
1067
1068impl<V> Iterator for Drain<'_, V> {
1069 type Item = (Entity, V);
1070
1071 fn next(&mut self) -> Option<Self::Item> {
1072 self.0.next()
1073 }
1074}
1075
1076impl<V> DoubleEndedIterator for Drain<'_, V> {
1077 fn next_back(&mut self) -> Option<Self::Item> {
1078 self.0.next_back()
1079 }
1080}
1081
1082impl<V> ExactSizeIterator for Drain<'_, V> {}
1083
1084impl<V> FusedIterator for Drain<'_, V> {}
1085
1086impl<V: Debug> Debug for Drain<'_, V> {
1087 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
1088 f.debug_tuple("Drain")
1089 .field(&self.0)
1090 .field(&self.1)
1091 .finish()
1092 }
1093}
1094
1095pub struct Keys<'a, V, S = EntityHash>(map::Keys<'a, Entity, V>, PhantomData<S>);
1100
1101impl<'a, V> Keys<'a, V> {
1102 pub fn into_inner(self) -> map::Keys<'a, Entity, V> {
1104 self.0
1105 }
1106}
1107
1108impl<'a, V, S> Deref for Keys<'a, V, S> {
1109 type Target = map::Keys<'a, Entity, V>;
1110
1111 fn deref(&self) -> &Self::Target {
1112 &self.0
1113 }
1114}
1115
1116impl<'a, V> Iterator for Keys<'a, V> {
1117 type Item = &'a Entity;
1118
1119 fn next(&mut self) -> Option<Self::Item> {
1120 self.0.next()
1121 }
1122}
1123
1124impl<V> DoubleEndedIterator for Keys<'_, V> {
1125 fn next_back(&mut self) -> Option<Self::Item> {
1126 self.0.next_back()
1127 }
1128}
1129
1130impl<V> ExactSizeIterator for Keys<'_, V> {}
1131
1132impl<V> FusedIterator for Keys<'_, V> {}
1133
1134impl<V> Index<usize> for Keys<'_, V> {
1135 type Output = Entity;
1136
1137 fn index(&self, index: usize) -> &Entity {
1138 self.0.index(index)
1139 }
1140}
1141
1142impl<V> Clone for Keys<'_, V> {
1143 fn clone(&self) -> Self {
1144 Self(self.0.clone(), PhantomData)
1145 }
1146}
1147
1148impl<V: Debug> Debug for Keys<'_, V> {
1149 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
1150 f.debug_tuple("Keys").field(&self.0).field(&self.1).finish()
1151 }
1152}
1153
1154impl<V> Default for Keys<'_, V> {
1155 fn default() -> Self {
1156 Self(Default::default(), PhantomData)
1157 }
1158}
1159
1160unsafe impl<V> EntitySetIterator for Keys<'_, V> {}
1162
1163pub struct IntoKeys<V, S = EntityHash>(map::IntoKeys<Entity, V>, PhantomData<S>);
1168
1169impl<V> IntoKeys<V> {
1170 pub fn into_inner(self) -> map::IntoKeys<Entity, V> {
1172 self.0
1173 }
1174}
1175
1176impl<V> Deref for IntoKeys<V> {
1177 type Target = map::IntoKeys<Entity, V>;
1178
1179 fn deref(&self) -> &Self::Target {
1180 &self.0
1181 }
1182}
1183
1184impl<V> Iterator for IntoKeys<V> {
1185 type Item = Entity;
1186
1187 fn next(&mut self) -> Option<Self::Item> {
1188 self.0.next()
1189 }
1190}
1191
1192impl<V> DoubleEndedIterator for IntoKeys<V> {
1193 fn next_back(&mut self) -> Option<Self::Item> {
1194 self.0.next_back()
1195 }
1196}
1197
1198impl<V> ExactSizeIterator for IntoKeys<V> {}
1199
1200impl<V> FusedIterator for IntoKeys<V> {}
1201
1202impl<V: Debug> Debug for IntoKeys<V> {
1203 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
1204 f.debug_tuple("IntoKeys")
1205 .field(&self.0)
1206 .field(&self.1)
1207 .finish()
1208 }
1209}
1210
1211impl<V> Default for IntoKeys<V> {
1212 fn default() -> Self {
1213 Self(Default::default(), PhantomData)
1214 }
1215}
1216
1217unsafe impl<V> EntitySetIterator for IntoKeys<V> {}