From the Rust unzip standard library:
fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB) where FromA: Default + Extend<A>, FromB: Default + Extend<B>, Self: Sized + Iterator<Item=(A, B)>, { struct SizeHint<A>(usize, Option<usize>, marker::PhantomData<A>); impl<A> Iterator for SizeHint<A> { type Item = A; fn next(&mut self) -> Option<A> { None } fn size_hint(&self) -> (usize, Option<usize>) { (self.0, self.1) } } let (lo, hi) = self.size_hint(); let mut ts: FromA = Default::default(); let mut us: FromB = Default::default(); ts.extend(SizeHint(lo, hi, marker::PhantomData)); us.extend(SizeHint(lo, hi, marker::PhantomData)); for (t, u) in self { ts.extend(Some(t)); us.extend(Some(u)); } (ts, us) }
These two lines:
ts.extend(SizeHint(lo, hi, marker::PhantomData)); us.extend(SizeHint(lo, hi, marker::PhantomData));
don't actually extend ts or us anything, as the next SizeHint method returns None . What is the purpose of this?
rust
qed
source share