use crate::{
transformations::{
ChainedCol, FilteredCol, FlattenedCol, FusedCol, ReversedCol, SkippedCol, SkippedWhileCol,
SteppedByCol, TakenCol, TakenWhileCol,
},
Collection, Iterable,
};
pub trait CollectionMut: Collection {
type IterMut<'i>: Iterator<Item = &'i mut Self::Item>
where
Self: 'i;
fn iter_mut(&mut self) -> Self::IterMut<'_>;
fn chained_mut<'a, I>(
&'a mut self,
other: &'a mut I,
) -> ChainedCol<Self, I, &'a mut Self, &'a mut I>
where
Self: Sized,
I: CollectionMut<Item = Self::Item>,
{
ChainedCol {
it1: self,
it2: other,
phantom: Default::default(),
}
}
fn filtered_mut<P>(&mut self, filter: P) -> FilteredCol<Self, &mut Self, P>
where
Self: Sized,
P: Fn(&Self::Item) -> bool + Copy,
{
FilteredCol {
it: self,
filter,
phantom: Default::default(),
}
}
fn flattened_mut(&mut self) -> FlattenedCol<Self, &mut Self>
where
Self: Sized,
Self::Item: IntoIterator,
for<'i> &'i Self::Item: IntoIterator<Item = &'i <Self::Item as IntoIterator>::Item>,
for<'i> &'i mut Self::Item: IntoIterator<Item = &'i mut <Self::Item as IntoIterator>::Item>,
{
FlattenedCol {
it: self,
phantom: Default::default(),
}
}
fn fused_mut(&mut self) -> FusedCol<Self, &mut Self>
where
Self: Sized,
{
FusedCol {
it: self,
phantom: Default::default(),
}
}
fn reversed_mut(&mut self) -> ReversedCol<Self, &mut Self>
where
Self: Sized,
for<'b> <Self::Iterable<'b> as Iterable>::Iter: DoubleEndedIterator,
for<'b> Self::IterMut<'b>: DoubleEndedIterator,
{
ReversedCol {
it: self,
phantom: Default::default(),
}
}
fn skipped_mut(&mut self, n: usize) -> SkippedCol<Self, &mut Self>
where
Self: Sized,
{
SkippedCol {
it: self,
n,
phantom: Default::default(),
}
}
fn skipped_while_mut<P>(&mut self, skip_while: P) -> SkippedWhileCol<Self, &mut Self, P>
where
Self: Sized,
P: Fn(&Self::Item) -> bool + Copy,
{
SkippedWhileCol {
it: self,
skip_while,
phantom: Default::default(),
}
}
fn stepped_by_mut(&mut self, step: usize) -> SteppedByCol<Self, &mut Self>
where
Self: Sized,
{
SteppedByCol {
it: self,
step,
phantom: Default::default(),
}
}
fn taken_mut(&mut self, n: usize) -> TakenCol<Self, &mut Self>
where
Self: Sized,
{
TakenCol {
it: self,
n,
phantom: Default::default(),
}
}
fn taken_while_mut<P>(&mut self, take_while: P) -> TakenWhileCol<Self, &mut Self, P>
where
Self: Sized,
P: Fn(&Self::Item) -> bool + Copy,
{
TakenWhileCol {
it: self,
take_while,
phantom: Default::default(),
}
}
}
impl<X> CollectionMut for X
where
X: IntoIterator,
for<'a> &'a X: IntoIterator<Item = &'a <X as IntoIterator>::Item>,
for<'a> &'a mut X: IntoIterator<Item = &'a mut <X as IntoIterator>::Item>,
{
type IterMut<'i>
= <&'i mut X as IntoIterator>::IntoIter
where
Self: 'i;
fn iter_mut(&mut self) -> Self::IterMut<'_> {
<&mut X as IntoIterator>::into_iter(self)
}
}