}
/// Allows searches to terminate early with a value.
-// FIXME (#75744): remove the alias once the generics are in a better order and `C=()`.
-pub type ControlFlow<T> = std::ops::ControlFlow<(), T>;
+pub use std::ops::ControlFlow;
/// The status of a node in the depth-first search.
///
#[inline]
fn find<T, B>(
f: &mut impl FnMut(T) -> Option<B>,
- ) -> impl FnMut((), T) -> ControlFlow<(), B> + '_ {
+ ) -> impl FnMut((), T) -> ControlFlow<B> + '_ {
move |(), x| match f(x) {
Some(x) => ControlFlow::Break(x),
None => ControlFlow::CONTINUE,
flag: &'a mut bool,
p: &'a mut impl FnMut(&T) -> bool,
mut fold: impl FnMut(Acc, T) -> R + 'a,
- ) -> impl FnMut(Acc, T) -> ControlFlow<Acc, R> + 'a {
+ ) -> impl FnMut(Acc, T) -> ControlFlow<R, Acc> + 'a {
move |acc, x| {
if p(&x) {
ControlFlow::from_try(fold(acc, x))
fn check<T, Acc, R: Try<Ok = Acc>>(
mut n: usize,
mut fold: impl FnMut(Acc, T) -> R,
- ) -> impl FnMut(Acc, T) -> ControlFlow<Acc, R> {
+ ) -> impl FnMut(Acc, T) -> ControlFlow<R, Acc> {
move |acc, x| {
n -= 1;
let r = fold(acc, x);
fn check<'a, T, Acc, R: Try<Ok = Acc>>(
n: &'a mut usize,
mut fold: impl FnMut(Acc, T) -> R + 'a,
- ) -> impl FnMut(Acc, T) -> ControlFlow<Acc, R> + 'a {
+ ) -> impl FnMut(Acc, T) -> ControlFlow<R, Acc> + 'a {
move |acc, x| {
*n -= 1;
let r = fold(acc, x);
state: &'a mut St,
f: &'a mut impl FnMut(&mut St, T) -> Option<B>,
mut fold: impl FnMut(Acc, B) -> R + 'a,
- ) -> impl FnMut(Acc, T) -> ControlFlow<Acc, R> + 'a {
+ ) -> impl FnMut(Acc, T) -> ControlFlow<R, Acc> + 'a {
move |acc, x| match f(state, x) {
None => ControlFlow::Break(try { acc }),
Some(x) => ControlFlow::from_try(fold(acc, x)),
P: FnMut(&Self::Item) -> bool,
{
#[inline]
- fn check<T>(
- mut predicate: impl FnMut(&T) -> bool,
- ) -> impl FnMut((), T) -> ControlFlow<(), T> {
+ fn check<T>(mut predicate: impl FnMut(&T) -> bool) -> impl FnMut((), T) -> ControlFlow<T> {
move |(), x| {
if predicate(&x) { ControlFlow::Break(x) } else { ControlFlow::CONTINUE }
}
F: FnMut(Self::Item) -> bool,
{
#[inline]
- fn check<T>(mut f: impl FnMut(T) -> bool) -> impl FnMut((), T) -> ControlFlow<(), ()> {
+ fn check<T>(mut f: impl FnMut(T) -> bool) -> impl FnMut((), T) -> ControlFlow<()> {
move |(), x| {
if f(x) { ControlFlow::CONTINUE } else { ControlFlow::BREAK }
}
F: FnMut(Self::Item) -> bool,
{
#[inline]
- fn check<T>(mut f: impl FnMut(T) -> bool) -> impl FnMut((), T) -> ControlFlow<(), ()> {
+ fn check<T>(mut f: impl FnMut(T) -> bool) -> impl FnMut((), T) -> ControlFlow<()> {
move |(), x| {
if f(x) { ControlFlow::BREAK } else { ControlFlow::CONTINUE }
}
P: FnMut(&Self::Item) -> bool,
{
#[inline]
- fn check<T>(
- mut predicate: impl FnMut(&T) -> bool,
- ) -> impl FnMut((), T) -> ControlFlow<(), T> {
+ fn check<T>(mut predicate: impl FnMut(&T) -> bool) -> impl FnMut((), T) -> ControlFlow<T> {
move |(), x| {
if predicate(&x) { ControlFlow::Break(x) } else { ControlFlow::CONTINUE }
}
F: FnMut(Self::Item) -> Option<B>,
{
#[inline]
- fn check<T, B>(
- mut f: impl FnMut(T) -> Option<B>,
- ) -> impl FnMut((), T) -> ControlFlow<(), B> {
+ fn check<T, B>(mut f: impl FnMut(T) -> Option<B>) -> impl FnMut((), T) -> ControlFlow<B> {
move |(), x| match f(x) {
Some(x) => ControlFlow::Break(x),
None => ControlFlow::CONTINUE,
R: Try<Ok = bool>,
{
#[inline]
- fn check<F, T, R>(mut f: F) -> impl FnMut((), T) -> ControlFlow<(), Result<T, R::Error>>
+ fn check<F, T, R>(mut f: F) -> impl FnMut((), T) -> ControlFlow<Result<T, R::Error>>
where
F: FnMut(&T) -> R,
R: Try<Ok = bool>,
/// Used to make try_fold closures more like normal loops
#[unstable(feature = "control_flow_enum", reason = "new API", issue = "75744")]
#[derive(Debug, Clone, Copy, PartialEq)]
-pub enum ControlFlow<C, B> {
+pub enum ControlFlow<B, C = ()> {
/// Continue in the loop, using the given value for the next iteration
Continue(C),
/// Exit the loop, yielding the given value
}
#[unstable(feature = "control_flow_enum", reason = "new API", issue = "75744")]
-impl<C, B> Try for ControlFlow<C, B> {
+impl<B, C> Try for ControlFlow<B, C> {
type Ok = C;
type Error = B;
#[inline]
}
}
-impl<C, B> ControlFlow<C, B> {
+impl<B, C> ControlFlow<B, C> {
/// Returns `true` if this is a `Break` variant.
#[inline]
#[unstable(feature = "control_flow_enum", reason = "new API", issue = "75744")]
}
}
-impl<R: Try> ControlFlow<R::Ok, R> {
+impl<R: Try> ControlFlow<R, R::Ok> {
/// Create a `ControlFlow` from any type implementing `Try`.
#[unstable(feature = "control_flow_enum", reason = "new API", issue = "75744")]
#[inline]
}
}
-impl<B> ControlFlow<(), B> {
+impl<B> ControlFlow<B, ()> {
/// It's frequently the case that there's no value needed with `Continue`,
/// so this provides a way to avoid typing `(())`, if you prefer it.
///
pub const CONTINUE: Self = ControlFlow::Continue(());
}
-impl<C> ControlFlow<C, ()> {
+impl<C> ControlFlow<(), C> {
/// APIs like `try_for_each` don't need values with `Break`,
/// so this provides a way to avoid typing `(())`, if you prefer it.
///