Skip to content

Commit 41de9d3

Browse files
committed
feat: impl PeekingNext for {vec::Drain, array::IntoIter, string::Drain}
1 parent 6afbb36 commit 41de9d3

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/peeking_take_while.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,44 @@ impl<T> PeekingNext for ::alloc::vec::IntoIter<T> {
105105
}
106106
}
107107

108+
#[cfg(feature = "use_alloc")]
109+
impl<'a, T> PeekingNext for ::alloc::vec::Drain<'a, T> {
110+
fn peeking_next<F>(&mut self, accept: F) -> Option<Self::Item>
111+
where
112+
F: FnOnce(&Self::Item) -> bool,
113+
{
114+
match accept(self.as_slice().first()?) {
115+
true => self.next(),
116+
false => None,
117+
}
118+
}
119+
}
120+
121+
#[cfg(feature = "use_alloc")]
122+
impl<'a> PeekingNext for ::alloc::string::Drain<'a> {
123+
fn peeking_next<F>(&mut self, accept: F) -> Option<Self::Item>
124+
where
125+
F: FnOnce(&Self::Item) -> bool,
126+
{
127+
match accept(&self.as_str().chars().next()?) {
128+
true => self.next(),
129+
false => None,
130+
}
131+
}
132+
}
133+
134+
impl<T, const N: usize> PeekingNext for ::core::array::IntoIter<T, N> {
135+
fn peeking_next<F>(&mut self, accept: F) -> Option<Self::Item>
136+
where
137+
F: FnOnce(&Self::Item) -> bool,
138+
{
139+
match accept(self.as_slice().first()?) {
140+
true => self.next(),
141+
false => None,
142+
}
143+
}
144+
}
145+
108146
impl<T: Clone> PeekingNext for RepeatN<T> {
109147
fn peeking_next<F>(&mut self, accept: F) -> Option<Self::Item>
110148
where

0 commit comments

Comments
 (0)