|
3 | 3 | // can't split that into multiple files. |
4 | 4 |
|
5 | 5 | use crate::cmp::{self, Ordering}; |
6 | | -use crate::ops::{Add, Try}; |
| 6 | +use crate::ops::{Add, ControlFlow, Try}; |
7 | 7 |
|
8 | | -use super::super::LoopState; |
9 | 8 | use super::super::TrustedRandomAccess; |
10 | 9 | use super::super::{Chain, Cloned, Copied, Cycle, Enumerate, Filter, FilterMap, Fuse}; |
11 | 10 | use super::super::{FlatMap, Flatten}; |
@@ -2088,12 +2087,12 @@ pub trait Iterator { |
2088 | 2087 | F: FnMut(Self::Item) -> bool, |
2089 | 2088 | { |
2090 | 2089 | #[inline] |
2091 | | - fn check<T>(mut f: impl FnMut(T) -> bool) -> impl FnMut((), T) -> LoopState<(), ()> { |
| 2090 | + fn check<T>(mut f: impl FnMut(T) -> bool) -> impl FnMut((), T) -> ControlFlow<(), ()> { |
2092 | 2091 | move |(), x| { |
2093 | | - if f(x) { LoopState::Continue(()) } else { LoopState::Break(()) } |
| 2092 | + if f(x) { ControlFlow::Continue(()) } else { ControlFlow::Break(()) } |
2094 | 2093 | } |
2095 | 2094 | } |
2096 | | - self.try_fold((), check(f)) == LoopState::Continue(()) |
| 2095 | + self.try_fold((), check(f)) == ControlFlow::Continue(()) |
2097 | 2096 | } |
2098 | 2097 |
|
2099 | 2098 | /// Tests if any element of the iterator matches a predicate. |
@@ -2141,13 +2140,13 @@ pub trait Iterator { |
2141 | 2140 | F: FnMut(Self::Item) -> bool, |
2142 | 2141 | { |
2143 | 2142 | #[inline] |
2144 | | - fn check<T>(mut f: impl FnMut(T) -> bool) -> impl FnMut((), T) -> LoopState<(), ()> { |
| 2143 | + fn check<T>(mut f: impl FnMut(T) -> bool) -> impl FnMut((), T) -> ControlFlow<(), ()> { |
2145 | 2144 | move |(), x| { |
2146 | | - if f(x) { LoopState::Break(()) } else { LoopState::Continue(()) } |
| 2145 | + if f(x) { ControlFlow::Break(()) } else { ControlFlow::Continue(()) } |
2147 | 2146 | } |
2148 | 2147 | } |
2149 | 2148 |
|
2150 | | - self.try_fold((), check(f)) == LoopState::Break(()) |
| 2149 | + self.try_fold((), check(f)) == ControlFlow::Break(()) |
2151 | 2150 | } |
2152 | 2151 |
|
2153 | 2152 | /// Searches for an element of an iterator that satisfies a predicate. |
@@ -2203,9 +2202,9 @@ pub trait Iterator { |
2203 | 2202 | #[inline] |
2204 | 2203 | fn check<T>( |
2205 | 2204 | mut predicate: impl FnMut(&T) -> bool, |
2206 | | - ) -> impl FnMut((), T) -> LoopState<(), T> { |
| 2205 | + ) -> impl FnMut((), T) -> ControlFlow<(), T> { |
2207 | 2206 | move |(), x| { |
2208 | | - if predicate(&x) { LoopState::Break(x) } else { LoopState::Continue(()) } |
| 2207 | + if predicate(&x) { ControlFlow::Break(x) } else { ControlFlow::Continue(()) } |
2209 | 2208 | } |
2210 | 2209 | } |
2211 | 2210 |
|
@@ -2235,10 +2234,12 @@ pub trait Iterator { |
2235 | 2234 | F: FnMut(Self::Item) -> Option<B>, |
2236 | 2235 | { |
2237 | 2236 | #[inline] |
2238 | | - fn check<T, B>(mut f: impl FnMut(T) -> Option<B>) -> impl FnMut((), T) -> LoopState<(), B> { |
| 2237 | + fn check<T, B>( |
| 2238 | + mut f: impl FnMut(T) -> Option<B>, |
| 2239 | + ) -> impl FnMut((), T) -> ControlFlow<(), B> { |
2239 | 2240 | move |(), x| match f(x) { |
2240 | | - Some(x) => LoopState::Break(x), |
2241 | | - None => LoopState::Continue(()), |
| 2241 | + Some(x) => ControlFlow::Break(x), |
| 2242 | + None => ControlFlow::Continue(()), |
2242 | 2243 | } |
2243 | 2244 | } |
2244 | 2245 |
|
@@ -2274,15 +2275,15 @@ pub trait Iterator { |
2274 | 2275 | R: Try<Ok = bool>, |
2275 | 2276 | { |
2276 | 2277 | #[inline] |
2277 | | - fn check<F, T, R>(mut f: F) -> impl FnMut((), T) -> LoopState<(), Result<T, R::Error>> |
| 2278 | + fn check<F, T, R>(mut f: F) -> impl FnMut((), T) -> ControlFlow<(), Result<T, R::Error>> |
2278 | 2279 | where |
2279 | 2280 | F: FnMut(&T) -> R, |
2280 | 2281 | R: Try<Ok = bool>, |
2281 | 2282 | { |
2282 | 2283 | move |(), x| match f(&x).into_result() { |
2283 | | - Ok(false) => LoopState::Continue(()), |
2284 | | - Ok(true) => LoopState::Break(Ok(x)), |
2285 | | - Err(x) => LoopState::Break(Err(x)), |
| 2284 | + Ok(false) => ControlFlow::Continue(()), |
| 2285 | + Ok(true) => ControlFlow::Break(Ok(x)), |
| 2286 | + Err(x) => ControlFlow::Break(Err(x)), |
2286 | 2287 | } |
2287 | 2288 | } |
2288 | 2289 |
|
@@ -2352,10 +2353,14 @@ pub trait Iterator { |
2352 | 2353 | #[inline] |
2353 | 2354 | fn check<T>( |
2354 | 2355 | mut predicate: impl FnMut(T) -> bool, |
2355 | | - ) -> impl FnMut(usize, T) -> LoopState<usize, usize> { |
| 2356 | + ) -> impl FnMut(usize, T) -> ControlFlow<usize, usize> { |
2356 | 2357 | // The addition might panic on overflow |
2357 | 2358 | move |i, x| { |
2358 | | - if predicate(x) { LoopState::Break(i) } else { LoopState::Continue(Add::add(i, 1)) } |
| 2359 | + if predicate(x) { |
| 2360 | + ControlFlow::Break(i) |
| 2361 | + } else { |
| 2362 | + ControlFlow::Continue(Add::add(i, 1)) |
| 2363 | + } |
2359 | 2364 | } |
2360 | 2365 | } |
2361 | 2366 |
|
@@ -2411,10 +2416,10 @@ pub trait Iterator { |
2411 | 2416 | #[inline] |
2412 | 2417 | fn check<T>( |
2413 | 2418 | mut predicate: impl FnMut(T) -> bool, |
2414 | | - ) -> impl FnMut(usize, T) -> LoopState<usize, usize> { |
| 2419 | + ) -> impl FnMut(usize, T) -> ControlFlow<usize, usize> { |
2415 | 2420 | move |i, x| { |
2416 | 2421 | let i = i - 1; |
2417 | | - if predicate(x) { LoopState::Break(i) } else { LoopState::Continue(i) } |
| 2422 | + if predicate(x) { ControlFlow::Break(i) } else { ControlFlow::Continue(i) } |
2418 | 2423 | } |
2419 | 2424 | } |
2420 | 2425 |
|
|
0 commit comments