Vendor things

This commit is contained in:
John Doty 2024-03-08 11:03:01 -08:00
parent 5deceec006
commit 977e3c17e5
19434 changed files with 10682014 additions and 0 deletions

View file

@ -0,0 +1,45 @@
/// Copied from https://users.rust-lang.org/t/iterator-need-to-identify-the-last-element/8836/3
pub trait IdentifyLast: Iterator + Sized {
fn identify_last(self) -> Iter<Self>;
}
impl<It> IdentifyLast for It
where
It: Iterator,
{
fn identify_last(mut self) -> Iter<Self> {
let e = self.next();
Iter {
iter: self,
buffer: e,
}
}
}
pub struct Iter<It>
where
It: Iterator,
{
iter: It,
buffer: Option<It::Item>,
}
impl<It> Iterator for Iter<It>
where
It: Iterator,
{
type Item = (bool, It::Item);
fn next(&mut self) -> Option<Self::Item> {
match self.buffer.take() {
None => None,
Some(e) => match self.iter.next() {
None => Some((true, e)),
Some(f) => {
self.buffer = Some(f);
Some((false, e))
}
},
}
}
}