You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let mut last = None;
for x in self { last = Some(x); }
last
If the iterator implements DoubleEndedIterator, it should default to:
self.next_back()
Many standard library types manually implement this specialisation, but a blanket implementation would be nice too!
Another potential specialisation for nth with DoubleEndedIterator and ExactSizeIterator:
if self.len() - n < n {
for x in self.rev() {
if n == 0 { return Some(x) }
n -= 1;
}
} else {
for x in self {
if n == 0 { return Some(x) }
n -= 1;
}
}
None
There's a bunch of stuff here and it might be worth looking into what extra implementations the standard library has, and how we could potentially make this default using specialisation.
The text was updated successfully, but these errors were encountered:
Right now,
Iterator::last
defaults to:If the iterator implements
DoubleEndedIterator
, it should default to:Many standard library types manually implement this specialisation, but a blanket implementation would be nice too!
Another potential specialisation for
nth
withDoubleEndedIterator
andExactSizeIterator
:There's a bunch of stuff here and it might be worth looking into what extra implementations the standard library has, and how we could potentially make this default using specialisation.
The text was updated successfully, but these errors were encountered: