94. ControlFlow::is_break and is_continue — Ask the Flow Which Way It Went
Got a ControlFlow back from try_fold or a visitor and just want to know which variant you’re holding? Before 1.95 you either pattern-matched or reached for matches!. Rust 1.95 adds straightforward .is_break() and .is_continue() methods.
The old pain
ControlFlow<B, C> is the enum that powers short-circuiting iterator methods like try_for_each and try_fold. Once you had one, checking which arm it was took more ceremony than you’d expect:
| |
The name ControlFlow::Break also collides visually with loop break, so code like this reads a bit awkwardly.
The fix: inherent is_break / is_continue
Rust 1.95 stabilises two one-line accessors, mirroring Result::is_ok / is_err and Option::is_some / is_none:
| |
No pattern, no import of a macro, no wildcards.
Handy in counting and filtering
Because the methods take &self, you can pipe results straight through iterator adapters:
| |
Previously you’d write |f| matches!(f, ControlFlow::Break(_)) — shorter, but noisier and requires you to name the variant (which means a use or a fully-qualified path).
It’s just a bool — but it’s the right bool
Nothing here is groundbreaking: you could always write a matches!. But when a method exists on Result and Option and Poll and hash iterators and even Peekable, not having one on ControlFlow meant reaching for a different idiom for no good reason. 1.95 closes that small gap.
Stabilised in Rust 1.95 (April 2026).