3 ms·
ControlFlow https://doc.rust-lang.org/core/ops/enum.ControlFlow.html https://doc.rust-lang.org/core/ops/enum.ControlFlow.html is awesome. Aside from its actual
by tialaramex 4y ago
ControlFlow https://doc.rust-lang.org/core/ops/enum.ControlFlow.html https://doc.rust-lang.org/core/ops/enum.ControlFlow.html is awesome.
Aside from its actual purpose (as part of making ? less magic, described in this trivia list) it's good to agree how to talk about control flow in the type system. If two unrelated pieces of software both care about control flow, in a lot of languages they'd both make up their own ways to signal "keep going" versus "halt". But since core::ops::ControlFlow exists in Rust it makes sense to use that, and so you spend less time writing adaptors. This is one of the main purposes of a standard library (notice this is in core not just std and so it's available even in a tiny embedded device with no allocator if you want it)
- DylanSp 4y agoIt's neat that there's work to make ? less magic and more general. The postfix ? for working with Option and Result is a really nice syntactic touch in Rust that makes it easy to work with those types in imperative-ish code, without requiring a bunch of map() or and_then() calls.