From aa310a561f9b6f430db74cf1dda30192501869e3 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 24 Feb 2021 14:22:29 -0500 Subject: exhaustive: Add a wrapper type for IntoIterator --- src/exhaustive.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/exhaustive.rs b/src/exhaustive.rs index 37af4c6..320994e 100644 --- a/src/exhaustive.rs +++ b/src/exhaustive.rs @@ -43,20 +43,24 @@ impl FromIterator for ExhaustiveSearch { } } -impl IntoIterator for ExhaustiveSearch { +/// An iterator that moves values out of an exhaustive index. +#[derive(Debug)] +pub struct IntoIter(std::vec::IntoIter); + +impl Iterator for IntoIter { type Item = T; - type IntoIter = std::vec::IntoIter; - fn into_iter(self) -> Self::IntoIter { - self.0.into_iter() + fn next(&mut self) -> Option { + self.0.next() } } -impl Extend for ExhaustiveSearch { - fn extend>(&mut self, iter: I) { - for value in iter { - self.push(value); - } +impl IntoIterator for ExhaustiveSearch { + type Item = T; + type IntoIter = IntoIter; + + fn into_iter(self) -> Self::IntoIter { + IntoIter(self.0.into_iter()) } } -- cgit v1.2.3