no-break

Crates.iono-break
lib.rsno-break
version
sourcesrc
created_at2024-12-01 13:37:10.895604
updated_at2024-12-01 13:44:00.398302
descriptionTypesafe extraction of continuation values from unbreakable control flows
homepage
repositoryhttps://github.com/vigna/no-break-rs
max_upload_size
id1467453
Cargo.toml error:TOML parse error at line 19, column 1 | 19 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Sebastiano Vigna (vigna)

documentation

README

Typesafe Extraction of Continuation Values from Unbreakable Control Flows

This crate provides a convenience extension trait NoBreak adding a method continue_value_no_break to ControlFlow types in which the type of the value contained in the break variant is Unbreakable. The purpose is identical to that of the unwrap_infallible crate, but for control flows.

Unbreakable is a marker type similar to Infallible (it is an empty enum), but with a different name as breaks in a control flow are not thought of as errors. It should ultimately be replaced with the never type.

Using continue_value_no_break on a ControlFlow forces a typesafe, compile-time check that the control flow will never break, and extracts the value from the only possible variant. In particular, type inference should make it possible to use expressions such as ControlFlow::Continue(value) without specifying the break type.

Examples

use no_break::NoBreak;
use std::ops::ControlFlow;

fn never_breaks<B>() -> ControlFlow<B, usize> {
    // Note that we do not need to specify B
    ControlFlow::Continue(5)
}
fn main() {
    // Type inference takes care of setting B to Unbreakable
    println!("{}", never_breaks().continue_value_no_break());
}
Commit count: 6

cargo fmt