-
-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add StreamingIteratorMut
and DoubleEndedStreamingIteratorMut
#23
Conversation
BTW, it occured to me that |
I've been using this for a while now and I've found #[inline]
fn find_mut<F>(&mut self, mut f: F) -> Option<&mut Self::Item>
where
Self: Sized,
F: FnMut(&Self::Item) -> bool,
{
loop {
self.advance();
match self.get() {
Some(i) => if f(i) {
break;
},
None => break,
}
}
(*self).get_mut()
} |
Hmm, you could also write |
it does what i need, once you know it, but I doubt most people using the crate would come to the conclusion that you can do that. |
Also I think the non mutable borrow is coherent with something like: |
I don't know, that pattern has more possibilities too, so maybe we should teach it. For example, a hypothetical |
Yes that makes sense perhaps it's just a matter of showing it in the documentation |
These are extensions of their non-`Mut` counterparts, in short: ```rust pub trait StreamingIteratorMut: StreamingIterator { fn get_mut(&mut self) -> Option<&mut Self::Item>; fn next_mut(&mut self) -> Option<&mut Self::Item>; fn fold_mut<B, F>(mut self, init: B, mut f: F) -> B where Self: Sized, F: FnMut(B, &mut Self::Item) -> B; fn for_each_mut<F>(self, mut f: F) where Self: Sized, F: FnMut(&mut Self::Item); } pub trait DoubleEndedStreamingIteratorMut: DoubleEndedStreamingIterator + StreamingIteratorMut { fn next_back_mut(&mut self) -> Option<&mut Self::Item>; fn rfold_mut<B, F>(mut self, init: B, mut f: F) -> B where Self: Sized, F: FnMut(B, &mut Self::Item) -> B; } ``` Only `get_mut` is required, and the rest have default implementations. There is also a new conversion from `Iterator`: ```rust pub fn convert_mut<'a, I, T: ?Sized>(iterator: I) -> ConvertMut<'a, I::IntoIter, T> where I: IntoIterator<Item = &'a mut T>; ```
In addition, these traits are implemented by all existing types that are able.
Fixes #21.