1use core::{
4 array::TryFromSliceError,
5 borrow::Borrow,
6 cmp::Ordering,
7 fmt::Debug,
8 iter::FusedIterator,
9 ops::{
10 Bound, Deref, Index, IndexMut, Range, RangeFrom, RangeFull, RangeInclusive, RangeTo,
11 RangeToInclusive,
12 },
13 ptr,
14 slice::{self, SliceIndex},
15};
16
17use alloc::{
18 borrow::{Cow, ToOwned},
19 boxed::Box,
20 collections::VecDeque,
21 rc::Rc,
22 vec::Vec,
23};
24
25use bevy_platform::sync::Arc;
26
27use super::{
28 unique_vec::{self, UniqueEntityEquivalentVec},
29 Entity, EntityEquivalent, EntitySet, EntitySetIterator, FromEntitySetIterator,
30 UniqueEntityEquivalentArray, UniqueEntityIter,
31};
32
33#[repr(transparent)]
39#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
40pub struct UniqueEntityEquivalentSlice<T: EntityEquivalent>([T]);
41
42pub type UniqueEntitySlice = UniqueEntityEquivalentSlice<Entity>;
46
47impl<T: EntityEquivalent> UniqueEntityEquivalentSlice<T> {
48 pub const unsafe fn from_slice_unchecked(slice: &[T]) -> &Self {
54 unsafe { &*(ptr::from_ref(slice) as *const Self) }
56 }
57
58 pub const unsafe fn from_slice_unchecked_mut(slice: &mut [T]) -> &mut Self {
64 unsafe { &mut *(ptr::from_mut(slice) as *mut Self) }
66 }
67
68 pub const fn as_inner(&self) -> &[T] {
70 &self.0
71 }
72
73 pub unsafe fn from_boxed_slice_unchecked(slice: Box<[T]>) -> Box<Self> {
79 unsafe { Box::from_raw(Box::into_raw(slice) as *mut Self) }
81 }
82
83 pub fn into_boxed_inner(self: Box<Self>) -> Box<[T]> {
85 unsafe { Box::from_raw(Box::into_raw(self) as *mut [T]) }
87 }
88
89 pub unsafe fn from_arc_slice_unchecked(slice: Arc<[T]>) -> Arc<Self> {
95 unsafe { Arc::from_raw(Arc::into_raw(slice) as *mut Self) }
97 }
98
99 pub fn into_arc_inner(this: Arc<Self>) -> Arc<[T]> {
101 unsafe { Arc::from_raw(Arc::into_raw(this) as *mut [T]) }
103 }
104
105 pub unsafe fn from_rc_slice_unchecked(slice: Rc<[T]>) -> Rc<Self> {
111 unsafe { Rc::from_raw(Rc::into_raw(slice) as *mut Self) }
113 }
114
115 pub fn into_rc_inner(self: Rc<Self>) -> Rc<[T]> {
117 unsafe { Rc::from_raw(Rc::into_raw(self) as *mut [T]) }
119 }
120
121 pub const fn split_first(&self) -> Option<(&T, &Self)> {
125 let Some((first, rest)) = self.0.split_first() else {
126 return None;
127 };
128 Some((first, unsafe { Self::from_slice_unchecked(rest) }))
130 }
131
132 pub const fn split_last(&self) -> Option<(&T, &Self)> {
136 let Some((last, rest)) = self.0.split_last() else {
137 return None;
138 };
139 Some((last, unsafe { Self::from_slice_unchecked(rest) }))
141 }
142
143 pub const fn first_chunk<const N: usize>(&self) -> Option<&UniqueEntityEquivalentArray<T, N>> {
147 let Some(chunk) = self.0.first_chunk() else {
148 return None;
149 };
150 Some(unsafe { UniqueEntityEquivalentArray::from_array_ref_unchecked(chunk) })
152 }
153
154 pub const fn split_first_chunk<const N: usize>(
158 &self,
159 ) -> Option<(
160 &UniqueEntityEquivalentArray<T, N>,
161 &UniqueEntityEquivalentSlice<T>,
162 )> {
163 let Some((chunk, rest)) = self.0.split_first_chunk() else {
164 return None;
165 };
166 unsafe {
168 Some((
169 UniqueEntityEquivalentArray::from_array_ref_unchecked(chunk),
170 Self::from_slice_unchecked(rest),
171 ))
172 }
173 }
174
175 pub const fn split_last_chunk<const N: usize>(
179 &self,
180 ) -> Option<(
181 &UniqueEntityEquivalentSlice<T>,
182 &UniqueEntityEquivalentArray<T, N>,
183 )> {
184 let Some((rest, chunk)) = self.0.split_last_chunk() else {
185 return None;
186 };
187 unsafe {
189 Some((
190 Self::from_slice_unchecked(rest),
191 UniqueEntityEquivalentArray::from_array_ref_unchecked(chunk),
192 ))
193 }
194 }
195
196 pub const fn last_chunk<const N: usize>(&self) -> Option<&UniqueEntityEquivalentArray<T, N>> {
200 let Some(chunk) = self.0.last_chunk() else {
201 return None;
202 };
203 Some(unsafe { UniqueEntityEquivalentArray::from_array_ref_unchecked(chunk) })
205 }
206
207 pub fn get<I>(&self, index: I) -> Option<&Self>
215 where
216 Self: Index<I>,
217 I: SliceIndex<[T], Output = [T]>,
218 {
219 self.0.get(index).map(|slice|
220 unsafe { Self::from_slice_unchecked(slice) })
222 }
223
224 pub fn get_mut<I>(&mut self, index: I) -> Option<&mut Self>
232 where
233 Self: Index<I>,
234 I: SliceIndex<[T], Output = [T]>,
235 {
236 self.0.get_mut(index).map(|slice|
237 unsafe { Self::from_slice_unchecked_mut(slice) })
239 }
240
241 pub unsafe fn get_unchecked<I>(&self, index: I) -> &Self
253 where
254 Self: Index<I>,
255 I: SliceIndex<[T], Output = [T]>,
256 {
257 unsafe { Self::from_slice_unchecked(self.0.get_unchecked(index)) }
259 }
260 pub unsafe fn get_unchecked_mut<I>(&mut self, index: I) -> &mut Self
272 where
273 Self: Index<I>,
274 I: SliceIndex<[T], Output = [T]>,
275 {
276 unsafe { Self::from_slice_unchecked_mut(self.0.get_unchecked_mut(index)) }
278 }
279
280 pub const fn as_mut_ptr(&mut self) -> *mut T {
282 self.0.as_mut_ptr()
283 }
284
285 pub const fn as_mut_ptr_range(&mut self) -> Range<*mut T> {
287 self.0.as_mut_ptr_range()
288 }
289
290 pub fn swap(&mut self, a: usize, b: usize) {
292 self.0.swap(a, b);
293 }
294
295 pub fn reverse(&mut self) {
297 self.0.reverse();
298 }
299
300 pub fn iter(&self) -> Iter<'_, T> {
302 unsafe { UniqueEntityIter::from_iterator_unchecked(self.0.iter()) }
304 }
305
306 pub fn windows(&self, size: usize) -> Windows<'_, T> {
313 unsafe {
315 UniqueEntityEquivalentSliceIter::from_slice_iterator_unchecked(self.0.windows(size))
316 }
317 }
318
319 pub fn chunks(&self, chunk_size: usize) -> Chunks<'_, T> {
326 unsafe {
328 UniqueEntityEquivalentSliceIter::from_slice_iterator_unchecked(
329 self.0.chunks(chunk_size),
330 )
331 }
332 }
333
334 pub fn chunks_mut(&mut self, chunk_size: usize) -> ChunksMut<'_, T> {
341 unsafe {
343 UniqueEntityEquivalentSliceIterMut::from_mut_slice_iterator_unchecked(
344 self.0.chunks_mut(chunk_size),
345 )
346 }
347 }
348
349 pub fn chunks_exact(&self, chunk_size: usize) -> ChunksExact<'_, T> {
355 unsafe {
357 UniqueEntityEquivalentSliceIter::from_slice_iterator_unchecked(
358 self.0.chunks_exact(chunk_size),
359 )
360 }
361 }
362
363 pub fn chunks_exact_mut(&mut self, chunk_size: usize) -> ChunksExactMut<'_, T> {
370 unsafe {
372 UniqueEntityEquivalentSliceIterMut::from_mut_slice_iterator_unchecked(
373 self.0.chunks_exact_mut(chunk_size),
374 )
375 }
376 }
377
378 pub fn rchunks(&self, chunk_size: usize) -> RChunks<'_, T> {
385 unsafe {
387 UniqueEntityEquivalentSliceIter::from_slice_iterator_unchecked(
388 self.0.rchunks(chunk_size),
389 )
390 }
391 }
392
393 pub fn rchunks_mut(&mut self, chunk_size: usize) -> RChunksMut<'_, T> {
400 unsafe {
402 UniqueEntityEquivalentSliceIterMut::from_mut_slice_iterator_unchecked(
403 self.0.rchunks_mut(chunk_size),
404 )
405 }
406 }
407
408 pub fn rchunks_exact(&self, chunk_size: usize) -> RChunksExact<'_, T> {
415 unsafe {
417 UniqueEntityEquivalentSliceIter::from_slice_iterator_unchecked(
418 self.0.rchunks_exact(chunk_size),
419 )
420 }
421 }
422
423 pub fn rchunks_exact_mut(&mut self, chunk_size: usize) -> RChunksExactMut<'_, T> {
430 unsafe {
432 UniqueEntityEquivalentSliceIterMut::from_mut_slice_iterator_unchecked(
433 self.0.rchunks_exact_mut(chunk_size),
434 )
435 }
436 }
437
438 pub fn chunk_by<F>(&self, pred: F) -> ChunkBy<'_, F, T>
445 where
446 F: FnMut(&T, &T) -> bool,
447 {
448 unsafe {
450 UniqueEntityEquivalentSliceIter::from_slice_iterator_unchecked(self.0.chunk_by(pred))
451 }
452 }
453
454 pub fn chunk_by_mut<F>(&mut self, pred: F) -> ChunkByMut<'_, F, T>
461 where
462 F: FnMut(&T, &T) -> bool,
463 {
464 unsafe {
466 UniqueEntityEquivalentSliceIterMut::from_mut_slice_iterator_unchecked(
467 self.0.chunk_by_mut(pred),
468 )
469 }
470 }
471
472 pub const fn split_at(&self, mid: usize) -> (&Self, &Self) {
476 let (left, right) = self.0.split_at(mid);
477 unsafe {
479 (
480 Self::from_slice_unchecked(left),
481 Self::from_slice_unchecked(right),
482 )
483 }
484 }
485
486 pub const fn split_at_mut(&mut self, mid: usize) -> (&mut Self, &mut Self) {
490 let (left, right) = self.0.split_at_mut(mid);
491 unsafe {
493 (
494 Self::from_slice_unchecked_mut(left),
495 Self::from_slice_unchecked_mut(right),
496 )
497 }
498 }
499
500 pub const unsafe fn split_at_unchecked(&self, mid: usize) -> (&Self, &Self) {
510 let (left, right) = unsafe { self.0.split_at_unchecked(mid) };
512 unsafe {
514 (
515 Self::from_slice_unchecked(left),
516 Self::from_slice_unchecked(right),
517 )
518 }
519 }
520
521 pub const unsafe fn split_at_mut_unchecked(&mut self, mid: usize) -> (&mut Self, &mut Self) {
531 let (left, right) = unsafe { self.0.split_at_mut_unchecked(mid) };
533 unsafe {
535 (
536 Self::from_slice_unchecked_mut(left),
537 Self::from_slice_unchecked_mut(right),
538 )
539 }
540 }
541
542 pub const fn split_at_checked(&self, mid: usize) -> Option<(&Self, &Self)> {
547 let Some((left, right)) = self.0.split_at_checked(mid) else {
548 return None;
549 };
550 unsafe {
552 Some((
553 Self::from_slice_unchecked(left),
554 Self::from_slice_unchecked(right),
555 ))
556 }
557 }
558
559 pub const fn split_at_mut_checked(&mut self, mid: usize) -> Option<(&mut Self, &mut Self)> {
564 let Some((left, right)) = self.0.split_at_mut_checked(mid) else {
565 return None;
566 };
567 unsafe {
569 Some((
570 Self::from_slice_unchecked_mut(left),
571 Self::from_slice_unchecked_mut(right),
572 ))
573 }
574 }
575
576 pub fn split<F>(&self, pred: F) -> Split<'_, F, T>
583 where
584 F: FnMut(&T) -> bool,
585 {
586 unsafe {
588 UniqueEntityEquivalentSliceIter::from_slice_iterator_unchecked(self.0.split(pred))
589 }
590 }
591
592 pub fn split_mut<F>(&mut self, pred: F) -> SplitMut<'_, F, T>
599 where
600 F: FnMut(&T) -> bool,
601 {
602 unsafe {
604 UniqueEntityEquivalentSliceIterMut::from_mut_slice_iterator_unchecked(
605 self.0.split_mut(pred),
606 )
607 }
608 }
609
610 pub fn split_inclusive<F>(&self, pred: F) -> SplitInclusive<'_, F, T>
617 where
618 F: FnMut(&T) -> bool,
619 {
620 unsafe {
622 UniqueEntityEquivalentSliceIter::from_slice_iterator_unchecked(
623 self.0.split_inclusive(pred),
624 )
625 }
626 }
627
628 pub fn split_inclusive_mut<F>(&mut self, pred: F) -> SplitInclusiveMut<'_, F, T>
635 where
636 F: FnMut(&T) -> bool,
637 {
638 unsafe {
640 UniqueEntityEquivalentSliceIterMut::from_mut_slice_iterator_unchecked(
641 self.0.split_inclusive_mut(pred),
642 )
643 }
644 }
645
646 pub fn rsplit<F>(&self, pred: F) -> RSplit<'_, F, T>
653 where
654 F: FnMut(&T) -> bool,
655 {
656 unsafe {
658 UniqueEntityEquivalentSliceIter::from_slice_iterator_unchecked(self.0.rsplit(pred))
659 }
660 }
661
662 pub fn rsplit_mut<F>(&mut self, pred: F) -> RSplitMut<'_, F, T>
670 where
671 F: FnMut(&T) -> bool,
672 {
673 unsafe {
675 UniqueEntityEquivalentSliceIterMut::from_mut_slice_iterator_unchecked(
676 self.0.rsplit_mut(pred),
677 )
678 }
679 }
680
681 pub fn splitn<F>(&self, n: usize, pred: F) -> SplitN<'_, F, T>
688 where
689 F: FnMut(&T) -> bool,
690 {
691 unsafe {
693 UniqueEntityEquivalentSliceIter::from_slice_iterator_unchecked(self.0.splitn(n, pred))
694 }
695 }
696
697 pub fn splitn_mut<F>(&mut self, n: usize, pred: F) -> SplitNMut<'_, F, T>
704 where
705 F: FnMut(&T) -> bool,
706 {
707 unsafe {
709 UniqueEntityEquivalentSliceIterMut::from_mut_slice_iterator_unchecked(
710 self.0.splitn_mut(n, pred),
711 )
712 }
713 }
714
715 pub fn rsplitn<F>(&self, n: usize, pred: F) -> RSplitN<'_, F, T>
722 where
723 F: FnMut(&T) -> bool,
724 {
725 unsafe {
727 UniqueEntityEquivalentSliceIter::from_slice_iterator_unchecked(self.0.rsplitn(n, pred))
728 }
729 }
730
731 pub fn rsplitn_mut<F>(&mut self, n: usize, pred: F) -> RSplitNMut<'_, F, T>
738 where
739 F: FnMut(&T) -> bool,
740 {
741 unsafe {
743 UniqueEntityEquivalentSliceIterMut::from_mut_slice_iterator_unchecked(
744 self.0.rsplitn_mut(n, pred),
745 )
746 }
747 }
748
749 pub fn sort_unstable(&mut self)
753 where
754 T: Ord,
755 {
756 self.0.sort_unstable();
757 }
758
759 pub fn sort_unstable_by<F>(&mut self, compare: F)
764 where
765 F: FnMut(&T, &T) -> Ordering,
766 {
767 self.0.sort_unstable_by(compare);
768 }
769
770 pub fn sort_unstable_by_key<K, F>(&mut self, f: F)
775 where
776 F: FnMut(&T) -> K,
777 K: Ord,
778 {
779 self.0.sort_unstable_by_key(f);
780 }
781
782 pub fn rotate_left(&mut self, mid: usize) {
788 self.0.rotate_left(mid);
789 }
790
791 pub fn rotate_right(&mut self, mid: usize) {
797 self.0.rotate_right(mid);
798 }
799
800 pub fn sort(&mut self)
804 where
805 T: Ord,
806 {
807 self.0.sort();
808 }
809
810 pub fn sort_by<F>(&mut self, compare: F)
814 where
815 F: FnMut(&T, &T) -> Ordering,
816 {
817 self.0.sort_by(compare);
818 }
819
820 pub fn sort_by_key<K, F>(&mut self, f: F)
824 where
825 F: FnMut(&T) -> K,
826 K: Ord,
827 {
828 self.0.sort_by_key(f);
829 }
830
831 pub fn sort_by_cached_key<K, F>(&mut self, f: F)
835 where
836 F: FnMut(&T) -> K,
837 K: Ord,
838 {
839 self.0.sort_by_cached_key(f);
840 }
841
842 pub fn to_vec(&self) -> UniqueEntityEquivalentVec<T>
844 where
845 T: Clone,
846 {
847 unsafe { UniqueEntityEquivalentVec::from_vec_unchecked(self.0.to_vec()) }
849 }
850
851 pub fn into_vec(self: Box<Self>) -> UniqueEntityEquivalentVec<T> {
855 unsafe {
859 let len = self.len();
860 let vec = Vec::from_raw_parts(Box::into_raw(self).cast::<T>(), len, len);
861 UniqueEntityEquivalentVec::from_vec_unchecked(vec)
862 }
863 }
864}
865
866pub const fn from_ref<T: EntityEquivalent>(s: &T) -> &UniqueEntityEquivalentSlice<T> {
868 unsafe { UniqueEntityEquivalentSlice::from_slice_unchecked(slice::from_ref(s)) }
870}
871
872pub const fn from_mut<T: EntityEquivalent>(s: &mut T) -> &mut UniqueEntityEquivalentSlice<T> {
874 unsafe { UniqueEntityEquivalentSlice::from_slice_unchecked_mut(slice::from_mut(s)) }
876}
877
878pub const unsafe fn from_raw_parts<'a, T: EntityEquivalent>(
887 data: *const T,
888 len: usize,
889) -> &'a UniqueEntityEquivalentSlice<T> {
890 unsafe { UniqueEntityEquivalentSlice::from_slice_unchecked(slice::from_raw_parts(data, len)) }
892}
893
894pub const unsafe fn from_raw_parts_mut<'a, T: EntityEquivalent>(
903 data: *mut T,
904 len: usize,
905) -> &'a mut UniqueEntityEquivalentSlice<T> {
906 unsafe {
908 UniqueEntityEquivalentSlice::from_slice_unchecked_mut(slice::from_raw_parts_mut(data, len))
909 }
910}
911
912pub unsafe fn cast_slice_of_unique_entity_slice<'a, 'b, T: EntityEquivalent + 'a>(
918 slice: &'b [&'a [T]],
919) -> &'b [&'a UniqueEntityEquivalentSlice<T>] {
920 unsafe { &*(ptr::from_ref(slice) as *const [&UniqueEntityEquivalentSlice<T>]) }
922}
923
924pub unsafe fn cast_slice_of_unique_entity_slice_mut<'a, 'b, T: EntityEquivalent + 'a>(
930 slice: &'b mut [&'a [T]],
931) -> &'b mut [&'a UniqueEntityEquivalentSlice<T>] {
932 unsafe { &mut *(ptr::from_mut(slice) as *mut [&UniqueEntityEquivalentSlice<T>]) }
934}
935
936pub unsafe fn cast_slice_of_mut_unique_entity_slice_mut<'a, 'b, T: EntityEquivalent + 'a>(
942 slice: &'b mut [&'a mut [T]],
943) -> &'b mut [&'a mut UniqueEntityEquivalentSlice<T>] {
944 unsafe { &mut *(ptr::from_mut(slice) as *mut [&mut UniqueEntityEquivalentSlice<T>]) }
946}
947
948impl<'a, T: EntityEquivalent> IntoIterator for &'a UniqueEntityEquivalentSlice<T> {
949 type Item = &'a T;
950
951 type IntoIter = Iter<'a, T>;
952
953 fn into_iter(self) -> Self::IntoIter {
954 self.iter()
955 }
956}
957
958impl<'a, T: EntityEquivalent> IntoIterator for &'a Box<UniqueEntityEquivalentSlice<T>> {
959 type Item = &'a T;
960
961 type IntoIter = Iter<'a, T>;
962
963 fn into_iter(self) -> Self::IntoIter {
964 self.iter()
965 }
966}
967
968impl<T: EntityEquivalent> IntoIterator for Box<UniqueEntityEquivalentSlice<T>> {
969 type Item = T;
970
971 type IntoIter = unique_vec::IntoIter<T>;
972
973 fn into_iter(self) -> Self::IntoIter {
974 self.into_vec().into_iter()
975 }
976}
977
978impl<T: EntityEquivalent> Deref for UniqueEntityEquivalentSlice<T> {
979 type Target = [T];
980
981 fn deref(&self) -> &Self::Target {
982 &self.0
983 }
984}
985
986impl<T: EntityEquivalent> AsRef<[T]> for UniqueEntityEquivalentSlice<T> {
987 fn as_ref(&self) -> &[T] {
988 self
989 }
990}
991
992impl<T: EntityEquivalent> AsRef<Self> for UniqueEntityEquivalentSlice<T> {
993 fn as_ref(&self) -> &Self {
994 self
995 }
996}
997
998impl<T: EntityEquivalent> AsMut<Self> for UniqueEntityEquivalentSlice<T> {
999 fn as_mut(&mut self) -> &mut Self {
1000 self
1001 }
1002}
1003
1004impl<T: EntityEquivalent> Borrow<[T]> for UniqueEntityEquivalentSlice<T> {
1005 fn borrow(&self) -> &[T] {
1006 self
1007 }
1008}
1009
1010impl<T: EntityEquivalent + Clone> Clone for Box<UniqueEntityEquivalentSlice<T>> {
1011 fn clone(&self) -> Self {
1012 self.to_vec().into_boxed_slice()
1013 }
1014}
1015
1016impl<T: EntityEquivalent> Default for &UniqueEntityEquivalentSlice<T> {
1017 fn default() -> Self {
1018 unsafe { UniqueEntityEquivalentSlice::from_slice_unchecked(Default::default()) }
1020 }
1021}
1022
1023impl<T: EntityEquivalent> Default for &mut UniqueEntityEquivalentSlice<T> {
1024 fn default() -> Self {
1025 unsafe { UniqueEntityEquivalentSlice::from_slice_unchecked_mut(Default::default()) }
1027 }
1028}
1029
1030impl<T: EntityEquivalent> Default for Box<UniqueEntityEquivalentSlice<T>> {
1031 fn default() -> Self {
1032 unsafe { UniqueEntityEquivalentSlice::from_boxed_slice_unchecked(Default::default()) }
1034 }
1035}
1036
1037impl<T: EntityEquivalent + Clone> From<&UniqueEntityEquivalentSlice<T>>
1038 for Box<UniqueEntityEquivalentSlice<T>>
1039{
1040 fn from(value: &UniqueEntityEquivalentSlice<T>) -> Self {
1041 unsafe { UniqueEntityEquivalentSlice::from_boxed_slice_unchecked(value.0.into()) }
1043 }
1044}
1045
1046impl<T: EntityEquivalent + Clone> From<&UniqueEntityEquivalentSlice<T>>
1047 for Arc<UniqueEntityEquivalentSlice<T>>
1048{
1049 fn from(value: &UniqueEntityEquivalentSlice<T>) -> Self {
1050 unsafe { UniqueEntityEquivalentSlice::from_arc_slice_unchecked(value.0.into()) }
1052 }
1053}
1054
1055impl<T: EntityEquivalent + Clone> From<&UniqueEntityEquivalentSlice<T>>
1056 for Rc<UniqueEntityEquivalentSlice<T>>
1057{
1058 fn from(value: &UniqueEntityEquivalentSlice<T>) -> Self {
1059 unsafe { UniqueEntityEquivalentSlice::from_rc_slice_unchecked(value.0.into()) }
1061 }
1062}
1063
1064impl<'a, T: EntityEquivalent + Clone> From<&'a UniqueEntityEquivalentSlice<T>>
1065 for Cow<'a, UniqueEntityEquivalentSlice<T>>
1066{
1067 fn from(value: &'a UniqueEntityEquivalentSlice<T>) -> Self {
1068 Cow::Borrowed(value)
1069 }
1070}
1071
1072impl<T: EntityEquivalent + Clone, const N: usize> From<UniqueEntityEquivalentArray<T, N>>
1073 for Box<UniqueEntityEquivalentSlice<T>>
1074{
1075 fn from(value: UniqueEntityEquivalentArray<T, N>) -> Self {
1076 unsafe {
1078 UniqueEntityEquivalentSlice::from_boxed_slice_unchecked(Box::new(value.into_inner()))
1079 }
1080 }
1081}
1082
1083impl<'a, T: EntityEquivalent + Clone> From<Cow<'a, UniqueEntityEquivalentSlice<T>>>
1084 for Box<UniqueEntityEquivalentSlice<T>>
1085{
1086 fn from(value: Cow<'a, UniqueEntityEquivalentSlice<T>>) -> Self {
1087 match value {
1088 Cow::Borrowed(slice) => Box::from(slice),
1089 Cow::Owned(slice) => Box::from(slice),
1090 }
1091 }
1092}
1093
1094impl<T: EntityEquivalent> From<UniqueEntityEquivalentVec<T>>
1095 for Box<UniqueEntityEquivalentSlice<T>>
1096{
1097 fn from(value: UniqueEntityEquivalentVec<T>) -> Self {
1098 value.into_boxed_slice()
1099 }
1100}
1101
1102impl<T: EntityEquivalent> FromIterator<T> for Box<UniqueEntityEquivalentSlice<T>> {
1103 fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self {
1104 iter.into_iter()
1105 .collect::<UniqueEntityEquivalentVec<T>>()
1106 .into_boxed_slice()
1107 }
1108}
1109
1110impl<T: EntityEquivalent> FromEntitySetIterator<T> for Box<UniqueEntityEquivalentSlice<T>> {
1111 fn from_entity_set_iter<I: EntitySet<Item = T>>(iter: I) -> Self {
1112 iter.into_iter()
1113 .collect_set::<UniqueEntityEquivalentVec<T>>()
1114 .into_boxed_slice()
1115 }
1116}
1117
1118impl<T: EntityEquivalent + PartialEq<U>, U: EntityEquivalent>
1119 PartialEq<UniqueEntityEquivalentVec<U>> for &UniqueEntityEquivalentSlice<T>
1120{
1121 fn eq(&self, other: &UniqueEntityEquivalentVec<U>) -> bool {
1122 self.0.eq(other.as_vec())
1123 }
1124}
1125
1126impl<T: EntityEquivalent + PartialEq<U>, U: EntityEquivalent>
1127 PartialEq<UniqueEntityEquivalentVec<U>> for &mut UniqueEntityEquivalentSlice<T>
1128{
1129 fn eq(&self, other: &UniqueEntityEquivalentVec<U>) -> bool {
1130 self.0.eq(other.as_vec())
1131 }
1132}
1133
1134impl<T: EntityEquivalent + PartialEq<U>, U: EntityEquivalent>
1135 PartialEq<UniqueEntityEquivalentVec<U>> for UniqueEntityEquivalentSlice<T>
1136{
1137 fn eq(&self, other: &UniqueEntityEquivalentVec<U>) -> bool {
1138 self.0.eq(other.as_vec())
1139 }
1140}
1141
1142impl<T: PartialEq<U>, U: EntityEquivalent, const N: usize>
1143 PartialEq<&UniqueEntityEquivalentSlice<U>> for [T; N]
1144{
1145 fn eq(&self, other: &&UniqueEntityEquivalentSlice<U>) -> bool {
1146 self.eq(&other.0)
1147 }
1148}
1149
1150impl<T: PartialEq<U> + Clone, U: EntityEquivalent> PartialEq<&UniqueEntityEquivalentSlice<U>>
1151 for Cow<'_, [T]>
1152{
1153 fn eq(&self, other: &&UniqueEntityEquivalentSlice<U>) -> bool {
1154 self.eq(&&other.0)
1155 }
1156}
1157
1158impl<T: EntityEquivalent + PartialEq<U> + Clone, U: EntityEquivalent>
1159 PartialEq<&UniqueEntityEquivalentSlice<U>> for Cow<'_, UniqueEntityEquivalentSlice<T>>
1160{
1161 fn eq(&self, other: &&UniqueEntityEquivalentSlice<U>) -> bool {
1162 self.0.eq(&other.0)
1163 }
1164}
1165
1166impl<T: PartialEq<U>, U: EntityEquivalent> PartialEq<&UniqueEntityEquivalentSlice<U>> for Vec<T> {
1167 fn eq(&self, other: &&UniqueEntityEquivalentSlice<U>) -> bool {
1168 self.eq(&other.0)
1169 }
1170}
1171
1172impl<T: PartialEq<U>, U: EntityEquivalent> PartialEq<&UniqueEntityEquivalentSlice<U>>
1173 for VecDeque<T>
1174{
1175 fn eq(&self, other: &&UniqueEntityEquivalentSlice<U>) -> bool {
1176 self.eq(&&other.0)
1177 }
1178}
1179
1180impl<T: PartialEq<U>, U: EntityEquivalent, const N: usize>
1181 PartialEq<&mut UniqueEntityEquivalentSlice<U>> for [T; N]
1182{
1183 fn eq(&self, other: &&mut UniqueEntityEquivalentSlice<U>) -> bool {
1184 self.eq(&other.0)
1185 }
1186}
1187
1188impl<T: PartialEq<U> + Clone, U: EntityEquivalent> PartialEq<&mut UniqueEntityEquivalentSlice<U>>
1189 for Cow<'_, [T]>
1190{
1191 fn eq(&self, other: &&mut UniqueEntityEquivalentSlice<U>) -> bool {
1192 self.eq(&&**other)
1193 }
1194}
1195
1196impl<T: EntityEquivalent + PartialEq<U> + Clone, U: EntityEquivalent>
1197 PartialEq<&mut UniqueEntityEquivalentSlice<U>> for Cow<'_, UniqueEntityEquivalentSlice<T>>
1198{
1199 fn eq(&self, other: &&mut UniqueEntityEquivalentSlice<U>) -> bool {
1200 self.0.eq(&other.0)
1201 }
1202}
1203
1204impl<T: EntityEquivalent + PartialEq<U> + Clone, U: EntityEquivalent>
1205 PartialEq<UniqueEntityEquivalentVec<U>> for Cow<'_, UniqueEntityEquivalentSlice<T>>
1206{
1207 fn eq(&self, other: &UniqueEntityEquivalentVec<U>) -> bool {
1208 self.0.eq(other.as_vec())
1209 }
1210}
1211
1212impl<T: PartialEq<U>, U: EntityEquivalent> PartialEq<&mut UniqueEntityEquivalentSlice<U>>
1213 for Vec<T>
1214{
1215 fn eq(&self, other: &&mut UniqueEntityEquivalentSlice<U>) -> bool {
1216 self.eq(&other.0)
1217 }
1218}
1219
1220impl<T: PartialEq<U>, U: EntityEquivalent> PartialEq<&mut UniqueEntityEquivalentSlice<U>>
1221 for VecDeque<T>
1222{
1223 fn eq(&self, other: &&mut UniqueEntityEquivalentSlice<U>) -> bool {
1224 self.eq(&&other.0)
1225 }
1226}
1227
1228impl<T: EntityEquivalent + PartialEq<U>, U: EntityEquivalent>
1229 PartialEq<UniqueEntityEquivalentSlice<U>> for [T]
1230{
1231 fn eq(&self, other: &UniqueEntityEquivalentSlice<U>) -> bool {
1232 self.eq(&other.0)
1233 }
1234}
1235
1236impl<T: PartialEq<U>, U: EntityEquivalent, const N: usize> PartialEq<UniqueEntityEquivalentSlice<U>>
1237 for [T; N]
1238{
1239 fn eq(&self, other: &UniqueEntityEquivalentSlice<U>) -> bool {
1240 self.eq(&other.0)
1241 }
1242}
1243
1244impl<T: EntityEquivalent + PartialEq<U>, U: EntityEquivalent>
1245 PartialEq<UniqueEntityEquivalentSlice<U>> for Vec<T>
1246{
1247 fn eq(&self, other: &UniqueEntityEquivalentSlice<U>) -> bool {
1248 self.eq(&other.0)
1249 }
1250}
1251
1252impl<T: EntityEquivalent + PartialEq<U>, U, const N: usize> PartialEq<[U; N]>
1253 for &UniqueEntityEquivalentSlice<T>
1254{
1255 fn eq(&self, other: &[U; N]) -> bool {
1256 self.0.eq(other)
1257 }
1258}
1259
1260impl<T: EntityEquivalent + PartialEq<U>, U, const N: usize> PartialEq<[U; N]>
1261 for &mut UniqueEntityEquivalentSlice<T>
1262{
1263 fn eq(&self, other: &[U; N]) -> bool {
1264 self.0.eq(other)
1265 }
1266}
1267
1268impl<T: EntityEquivalent + PartialEq<U>, U, const N: usize> PartialEq<[U; N]>
1269 for UniqueEntityEquivalentSlice<T>
1270{
1271 fn eq(&self, other: &[U; N]) -> bool {
1272 self.0.eq(other)
1273 }
1274}
1275
1276impl<T: EntityEquivalent + PartialEq<U>, U: EntityEquivalent, const N: usize>
1277 PartialEq<UniqueEntityEquivalentArray<U, N>> for &UniqueEntityEquivalentSlice<T>
1278{
1279 fn eq(&self, other: &UniqueEntityEquivalentArray<U, N>) -> bool {
1280 self.0.eq(&other.0)
1281 }
1282}
1283
1284impl<T: EntityEquivalent + PartialEq<U>, U: EntityEquivalent, const N: usize>
1285 PartialEq<UniqueEntityEquivalentArray<U, N>> for &mut UniqueEntityEquivalentSlice<T>
1286{
1287 fn eq(&self, other: &UniqueEntityEquivalentArray<U, N>) -> bool {
1288 self.0.eq(&other.0)
1289 }
1290}
1291
1292impl<T: EntityEquivalent + PartialEq<U>, U: EntityEquivalent, const N: usize>
1293 PartialEq<UniqueEntityEquivalentArray<U, N>> for UniqueEntityEquivalentSlice<T>
1294{
1295 fn eq(&self, other: &UniqueEntityEquivalentArray<U, N>) -> bool {
1296 self.0.eq(&other.0)
1297 }
1298}
1299
1300impl<T: EntityEquivalent + PartialEq<U>, U> PartialEq<Vec<U>> for &UniqueEntityEquivalentSlice<T> {
1301 fn eq(&self, other: &Vec<U>) -> bool {
1302 self.0.eq(other)
1303 }
1304}
1305
1306impl<T: EntityEquivalent + PartialEq<U>, U> PartialEq<Vec<U>>
1307 for &mut UniqueEntityEquivalentSlice<T>
1308{
1309 fn eq(&self, other: &Vec<U>) -> bool {
1310 self.0.eq(other)
1311 }
1312}
1313
1314impl<T: EntityEquivalent + PartialEq<U>, U> PartialEq<Vec<U>> for UniqueEntityEquivalentSlice<T> {
1315 fn eq(&self, other: &Vec<U>) -> bool {
1316 self.0.eq(other)
1317 }
1318}
1319
1320impl<T: EntityEquivalent + Clone> ToOwned for UniqueEntityEquivalentSlice<T> {
1321 type Owned = UniqueEntityEquivalentVec<T>;
1322
1323 fn to_owned(&self) -> Self::Owned {
1324 unsafe { UniqueEntityEquivalentVec::from_vec_unchecked(self.0.to_owned()) }
1326 }
1327}
1328
1329impl<'a, T: EntityEquivalent + Copy, const N: usize> TryFrom<&'a UniqueEntityEquivalentSlice<T>>
1330 for &'a UniqueEntityEquivalentArray<T, N>
1331{
1332 type Error = TryFromSliceError;
1333
1334 fn try_from(value: &'a UniqueEntityEquivalentSlice<T>) -> Result<Self, Self::Error> {
1335 <&[T; N]>::try_from(&value.0).map(|array|
1336 unsafe { UniqueEntityEquivalentArray::from_array_ref_unchecked(array) })
1338 }
1339}
1340
1341impl<T: EntityEquivalent + Copy, const N: usize> TryFrom<&UniqueEntityEquivalentSlice<T>>
1342 for UniqueEntityEquivalentArray<T, N>
1343{
1344 type Error = TryFromSliceError;
1345
1346 fn try_from(value: &UniqueEntityEquivalentSlice<T>) -> Result<Self, Self::Error> {
1347 <&Self>::try_from(value).copied()
1348 }
1349}
1350
1351impl<T: EntityEquivalent + Copy, const N: usize> TryFrom<&mut UniqueEntityEquivalentSlice<T>>
1352 for UniqueEntityEquivalentArray<T, N>
1353{
1354 type Error = TryFromSliceError;
1355
1356 fn try_from(value: &mut UniqueEntityEquivalentSlice<T>) -> Result<Self, Self::Error> {
1357 <Self>::try_from(&*value)
1358 }
1359}
1360
1361impl<T: EntityEquivalent> Index<(Bound<usize>, Bound<usize>)> for UniqueEntityEquivalentSlice<T> {
1362 type Output = Self;
1363 fn index(&self, key: (Bound<usize>, Bound<usize>)) -> &Self {
1364 unsafe { Self::from_slice_unchecked(self.0.index(key)) }
1366 }
1367}
1368
1369impl<T: EntityEquivalent> Index<Range<usize>> for UniqueEntityEquivalentSlice<T> {
1370 type Output = Self;
1371 fn index(&self, key: Range<usize>) -> &Self {
1372 unsafe { Self::from_slice_unchecked(self.0.index(key)) }
1374 }
1375}
1376
1377impl<T: EntityEquivalent> Index<RangeFrom<usize>> for UniqueEntityEquivalentSlice<T> {
1378 type Output = Self;
1379 fn index(&self, key: RangeFrom<usize>) -> &Self {
1380 unsafe { Self::from_slice_unchecked(self.0.index(key)) }
1382 }
1383}
1384
1385impl<T: EntityEquivalent> Index<RangeFull> for UniqueEntityEquivalentSlice<T> {
1386 type Output = Self;
1387 fn index(&self, key: RangeFull) -> &Self {
1388 unsafe { Self::from_slice_unchecked(self.0.index(key)) }
1390 }
1391}
1392
1393impl<T: EntityEquivalent> Index<RangeInclusive<usize>> for UniqueEntityEquivalentSlice<T> {
1394 type Output = UniqueEntityEquivalentSlice<T>;
1395 fn index(&self, key: RangeInclusive<usize>) -> &Self {
1396 unsafe { Self::from_slice_unchecked(self.0.index(key)) }
1398 }
1399}
1400
1401impl<T: EntityEquivalent> Index<RangeTo<usize>> for UniqueEntityEquivalentSlice<T> {
1402 type Output = UniqueEntityEquivalentSlice<T>;
1403 fn index(&self, key: RangeTo<usize>) -> &Self {
1404 unsafe { Self::from_slice_unchecked(self.0.index(key)) }
1406 }
1407}
1408
1409impl<T: EntityEquivalent> Index<RangeToInclusive<usize>> for UniqueEntityEquivalentSlice<T> {
1410 type Output = UniqueEntityEquivalentSlice<T>;
1411 fn index(&self, key: RangeToInclusive<usize>) -> &Self {
1412 unsafe { Self::from_slice_unchecked(self.0.index(key)) }
1414 }
1415}
1416
1417impl<T: EntityEquivalent> Index<usize> for UniqueEntityEquivalentSlice<T> {
1418 type Output = T;
1419
1420 fn index(&self, index: usize) -> &T {
1421 &self.0[index]
1422 }
1423}
1424
1425impl<T: EntityEquivalent> IndexMut<(Bound<usize>, Bound<usize>)>
1426 for UniqueEntityEquivalentSlice<T>
1427{
1428 fn index_mut(&mut self, key: (Bound<usize>, Bound<usize>)) -> &mut Self {
1429 unsafe { Self::from_slice_unchecked_mut(self.0.index_mut(key)) }
1431 }
1432}
1433
1434impl<T: EntityEquivalent> IndexMut<Range<usize>> for UniqueEntityEquivalentSlice<T> {
1435 fn index_mut(&mut self, key: Range<usize>) -> &mut Self {
1436 unsafe { Self::from_slice_unchecked_mut(self.0.index_mut(key)) }
1438 }
1439}
1440
1441impl<T: EntityEquivalent> IndexMut<RangeFrom<usize>> for UniqueEntityEquivalentSlice<T> {
1442 fn index_mut(&mut self, key: RangeFrom<usize>) -> &mut Self {
1443 unsafe { Self::from_slice_unchecked_mut(self.0.index_mut(key)) }
1445 }
1446}
1447
1448impl<T: EntityEquivalent> IndexMut<RangeFull> for UniqueEntityEquivalentSlice<T> {
1449 fn index_mut(&mut self, key: RangeFull) -> &mut Self {
1450 unsafe { Self::from_slice_unchecked_mut(self.0.index_mut(key)) }
1452 }
1453}
1454
1455impl<T: EntityEquivalent> IndexMut<RangeInclusive<usize>> for UniqueEntityEquivalentSlice<T> {
1456 fn index_mut(&mut self, key: RangeInclusive<usize>) -> &mut Self {
1457 unsafe { Self::from_slice_unchecked_mut(self.0.index_mut(key)) }
1459 }
1460}
1461
1462impl<T: EntityEquivalent> IndexMut<RangeTo<usize>> for UniqueEntityEquivalentSlice<T> {
1463 fn index_mut(&mut self, key: RangeTo<usize>) -> &mut Self {
1464 unsafe { Self::from_slice_unchecked_mut(self.0.index_mut(key)) }
1466 }
1467}
1468
1469impl<T: EntityEquivalent> IndexMut<RangeToInclusive<usize>> for UniqueEntityEquivalentSlice<T> {
1470 fn index_mut(&mut self, key: RangeToInclusive<usize>) -> &mut Self {
1471 unsafe { Self::from_slice_unchecked_mut(self.0.index_mut(key)) }
1473 }
1474}
1475
1476pub type Iter<'a, T> = UniqueEntityIter<slice::Iter<'a, T>>;
1483
1484impl<'a, T: EntityEquivalent> UniqueEntityIter<slice::Iter<'a, T>> {
1485 pub fn as_slice(&self) -> &'a UniqueEntityEquivalentSlice<T> {
1489 unsafe { UniqueEntityEquivalentSlice::from_slice_unchecked(self.as_inner().as_slice()) }
1491 }
1492}
1493
1494pub type IterMut<'a, T> = UniqueEntityIter<slice::IterMut<'a, T>>;
1496
1497impl<'a, T: EntityEquivalent> UniqueEntityIter<slice::IterMut<'a, T>> {
1498 pub fn into_slice(self) -> &'a mut UniqueEntityEquivalentSlice<T> {
1502 unsafe {
1504 UniqueEntityEquivalentSlice::from_slice_unchecked_mut(self.into_inner().into_slice())
1505 }
1506 }
1507
1508 pub fn as_slice(&self) -> &UniqueEntityEquivalentSlice<T> {
1512 unsafe { UniqueEntityEquivalentSlice::from_slice_unchecked(self.as_inner().as_slice()) }
1514 }
1515}
1516
1517#[derive(Debug)]
1520pub struct UniqueEntityEquivalentSliceIter<
1521 'a,
1522 T: EntityEquivalent + 'a,
1523 I: Iterator<Item = &'a [T]>,
1524> {
1525 pub(crate) iter: I,
1526}
1527
1528impl<'a, T: EntityEquivalent + 'a, I: Iterator<Item = &'a [T]>>
1529 UniqueEntityEquivalentSliceIter<'a, T, I>
1530{
1531 pub unsafe fn from_slice_iterator_unchecked(iter: I) -> Self {
1537 Self { iter }
1538 }
1539
1540 pub fn into_inner(self) -> I {
1542 self.iter
1543 }
1544
1545 pub fn as_inner(&self) -> &I {
1547 &self.iter
1548 }
1549
1550 pub unsafe fn as_mut_inner(&mut self) -> &mut I {
1557 &mut self.iter
1558 }
1559}
1560
1561impl<'a, T: EntityEquivalent + 'a, I: Iterator<Item = &'a [T]>> Iterator
1562 for UniqueEntityEquivalentSliceIter<'a, T, I>
1563{
1564 type Item = &'a UniqueEntityEquivalentSlice<T>;
1565
1566 fn next(&mut self) -> Option<Self::Item> {
1567 self.iter.next().map(|slice|
1568 unsafe { UniqueEntityEquivalentSlice::from_slice_unchecked(slice) })
1570 }
1571
1572 fn size_hint(&self) -> (usize, Option<usize>) {
1573 self.iter.size_hint()
1574 }
1575}
1576
1577impl<'a, T: EntityEquivalent + 'a, I: ExactSizeIterator<Item = &'a [T]>> ExactSizeIterator
1578 for UniqueEntityEquivalentSliceIter<'a, T, I>
1579{
1580}
1581
1582impl<'a, T: EntityEquivalent + 'a, I: DoubleEndedIterator<Item = &'a [T]>> DoubleEndedIterator
1583 for UniqueEntityEquivalentSliceIter<'a, T, I>
1584{
1585 fn next_back(&mut self) -> Option<Self::Item> {
1586 self.iter.next_back().map(|slice|
1587 unsafe { UniqueEntityEquivalentSlice::from_slice_unchecked(slice) })
1589 }
1590}
1591
1592impl<'a, T: EntityEquivalent + 'a, I: FusedIterator<Item = &'a [T]>> FusedIterator
1593 for UniqueEntityEquivalentSliceIter<'a, T, I>
1594{
1595}
1596
1597impl<'a, T: EntityEquivalent + 'a, I: Iterator<Item = &'a [T]> + AsRef<[&'a [T]]>>
1598 AsRef<[&'a UniqueEntityEquivalentSlice<T>]> for UniqueEntityEquivalentSliceIter<'a, T, I>
1599{
1600 fn as_ref(&self) -> &[&'a UniqueEntityEquivalentSlice<T>] {
1601 unsafe { cast_slice_of_unique_entity_slice(self.iter.as_ref()) }
1603 }
1604}
1605
1606pub type Windows<'a, T = Entity> = UniqueEntityEquivalentSliceIter<'a, T, slice::Windows<'a, T>>;
1610
1611pub type Chunks<'a, T = Entity> = UniqueEntityEquivalentSliceIter<'a, T, slice::Chunks<'a, T>>;
1616
1617pub type ChunksExact<'a, T = Entity> =
1622 UniqueEntityEquivalentSliceIter<'a, T, slice::ChunksExact<'a, T>>;
1623
1624impl<'a, T: EntityEquivalent> UniqueEntityEquivalentSliceIter<'a, T, slice::ChunksExact<'a, T>> {
1625 pub fn remainder(&self) -> &'a UniqueEntityEquivalentSlice<T> {
1630 unsafe { UniqueEntityEquivalentSlice::from_slice_unchecked(self.iter.remainder()) }
1632 }
1633}
1634
1635pub type RChunks<'a, T = Entity> = UniqueEntityEquivalentSliceIter<'a, T, slice::RChunks<'a, T>>;
1640
1641pub type RChunksExact<'a, T = Entity> =
1646 UniqueEntityEquivalentSliceIter<'a, T, slice::RChunksExact<'a, T>>;
1647
1648impl<'a, T: EntityEquivalent> UniqueEntityEquivalentSliceIter<'a, T, slice::RChunksExact<'a, T>> {
1649 pub fn remainder(&self) -> &'a UniqueEntityEquivalentSlice<T> {
1654 unsafe { UniqueEntityEquivalentSlice::from_slice_unchecked(self.iter.remainder()) }
1656 }
1657}
1658
1659pub type ChunkBy<'a, P, T = Entity> =
1663 UniqueEntityEquivalentSliceIter<'a, T, slice::ChunkBy<'a, T, P>>;
1664
1665pub type Split<'a, P, T = Entity> = UniqueEntityEquivalentSliceIter<'a, T, slice::Split<'a, T, P>>;
1670
1671pub type SplitInclusive<'a, P, T = Entity> =
1676 UniqueEntityEquivalentSliceIter<'a, T, slice::SplitInclusive<'a, T, P>>;
1677
1678pub type RSplit<'a, P, T = Entity> =
1683 UniqueEntityEquivalentSliceIter<'a, T, slice::RSplit<'a, T, P>>;
1684
1685pub type SplitN<'a, P, T = Entity> =
1690 UniqueEntityEquivalentSliceIter<'a, T, slice::SplitN<'a, T, P>>;
1691
1692pub type RSplitN<'a, P, T = Entity> =
1698 UniqueEntityEquivalentSliceIter<'a, T, slice::RSplitN<'a, T, P>>;
1699
1700#[derive(Debug)]
1703pub struct UniqueEntityEquivalentSliceIterMut<
1704 'a,
1705 T: EntityEquivalent + 'a,
1706 I: Iterator<Item = &'a mut [T]>,
1707> {
1708 pub(crate) iter: I,
1709}
1710
1711impl<'a, T: EntityEquivalent + 'a, I: Iterator<Item = &'a mut [T]>>
1712 UniqueEntityEquivalentSliceIterMut<'a, T, I>
1713{
1714 pub unsafe fn from_mut_slice_iterator_unchecked(iter: I) -> Self {
1720 Self { iter }
1721 }
1722
1723 pub fn into_inner(self) -> I {
1725 self.iter
1726 }
1727
1728 pub fn as_inner(&self) -> &I {
1730 &self.iter
1731 }
1732
1733 pub unsafe fn as_mut_inner(&mut self) -> &mut I {
1740 &mut self.iter
1741 }
1742}
1743
1744impl<'a, T: EntityEquivalent + 'a, I: Iterator<Item = &'a mut [T]>> Iterator
1745 for UniqueEntityEquivalentSliceIterMut<'a, T, I>
1746{
1747 type Item = &'a mut UniqueEntityEquivalentSlice<T>;
1748
1749 fn next(&mut self) -> Option<Self::Item> {
1750 self.iter.next().map(|slice|
1751 unsafe { UniqueEntityEquivalentSlice::from_slice_unchecked_mut(slice) })
1753 }
1754
1755 fn size_hint(&self) -> (usize, Option<usize>) {
1756 self.iter.size_hint()
1757 }
1758}
1759
1760impl<'a, T: EntityEquivalent + 'a, I: ExactSizeIterator<Item = &'a mut [T]>> ExactSizeIterator
1761 for UniqueEntityEquivalentSliceIterMut<'a, T, I>
1762{
1763}
1764
1765impl<'a, T: EntityEquivalent + 'a, I: DoubleEndedIterator<Item = &'a mut [T]>> DoubleEndedIterator
1766 for UniqueEntityEquivalentSliceIterMut<'a, T, I>
1767{
1768 fn next_back(&mut self) -> Option<Self::Item> {
1769 self.iter.next_back().map(|slice|
1770 unsafe { UniqueEntityEquivalentSlice::from_slice_unchecked_mut(slice) })
1772 }
1773}
1774
1775impl<'a, T: EntityEquivalent + 'a, I: FusedIterator<Item = &'a mut [T]>> FusedIterator
1776 for UniqueEntityEquivalentSliceIterMut<'a, T, I>
1777{
1778}
1779
1780impl<'a, T: EntityEquivalent + 'a, I: Iterator<Item = &'a mut [T]> + AsRef<[&'a [T]]>>
1781 AsRef<[&'a UniqueEntityEquivalentSlice<T>]> for UniqueEntityEquivalentSliceIterMut<'a, T, I>
1782{
1783 fn as_ref(&self) -> &[&'a UniqueEntityEquivalentSlice<T>] {
1784 unsafe { cast_slice_of_unique_entity_slice(self.iter.as_ref()) }
1786 }
1787}
1788
1789impl<'a, T: EntityEquivalent + 'a, I: Iterator<Item = &'a mut [T]> + AsMut<[&'a mut [T]]>>
1790 AsMut<[&'a mut UniqueEntityEquivalentSlice<T>]>
1791 for UniqueEntityEquivalentSliceIterMut<'a, T, I>
1792{
1793 fn as_mut(&mut self) -> &mut [&'a mut UniqueEntityEquivalentSlice<T>] {
1794 unsafe { cast_slice_of_mut_unique_entity_slice_mut(self.iter.as_mut()) }
1796 }
1797}
1798
1799pub type ChunksMut<'a, T = Entity> =
1804 UniqueEntityEquivalentSliceIterMut<'a, T, slice::ChunksMut<'a, T>>;
1805
1806pub type ChunksExactMut<'a, T = Entity> =
1811 UniqueEntityEquivalentSliceIterMut<'a, T, slice::ChunksExactMut<'a, T>>;
1812
1813impl<'a, T: EntityEquivalent>
1814 UniqueEntityEquivalentSliceIterMut<'a, T, slice::ChunksExactMut<'a, T>>
1815{
1816 pub fn into_remainder(self) -> &'a mut UniqueEntityEquivalentSlice<T> {
1821 unsafe { UniqueEntityEquivalentSlice::from_slice_unchecked_mut(self.iter.into_remainder()) }
1823 }
1824}
1825
1826pub type RChunksMut<'a, T = Entity> =
1831 UniqueEntityEquivalentSliceIterMut<'a, T, slice::RChunksMut<'a, T>>;
1832
1833pub type RChunksExactMut<'a, T = Entity> =
1838 UniqueEntityEquivalentSliceIterMut<'a, T, slice::RChunksExactMut<'a, T>>;
1839
1840impl<'a, T: EntityEquivalent>
1841 UniqueEntityEquivalentSliceIterMut<'a, T, slice::RChunksExactMut<'a, T>>
1842{
1843 pub fn into_remainder(self) -> &'a mut UniqueEntityEquivalentSlice<T> {
1848 unsafe { UniqueEntityEquivalentSlice::from_slice_unchecked_mut(self.iter.into_remainder()) }
1850 }
1851}
1852
1853pub type ChunkByMut<'a, P, T = Entity> =
1858 UniqueEntityEquivalentSliceIterMut<'a, T, slice::ChunkByMut<'a, T, P>>;
1859
1860pub type SplitMut<'a, P, T = Entity> =
1865 UniqueEntityEquivalentSliceIterMut<'a, T, slice::SplitMut<'a, T, P>>;
1866
1867pub type SplitInclusiveMut<'a, P, T = Entity> =
1873 UniqueEntityEquivalentSliceIterMut<'a, T, slice::SplitInclusiveMut<'a, T, P>>;
1874
1875pub type RSplitMut<'a, P, T = Entity> =
1880 UniqueEntityEquivalentSliceIterMut<'a, T, slice::RSplitMut<'a, T, P>>;
1881
1882pub type SplitNMut<'a, P, T = Entity> =
1887 UniqueEntityEquivalentSliceIterMut<'a, T, slice::SplitNMut<'a, T, P>>;
1888
1889pub type RSplitNMut<'a, P, T = Entity> =
1895 UniqueEntityEquivalentSliceIterMut<'a, T, slice::RSplitNMut<'a, T, P>>;