breaktarget 0.1.0

Implementation of nonlocal breaks in Rust
Documentation
  • Coverage
  • 100%
    4 out of 4 items documented1 out of 4 items with examples
  • Size
  • Source code size: 7.79 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.37 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 8s Average build duration of successful builds.
  • all releases: 8s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • mystor/breaktarget
    3 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • mystor

breaktarget

Build Status

The breaktarget module defines one type: The BreakTarget type. A value of this type may be obtained by invoking BreakTarget::deploy.

BreakTarget::deploy takes a lambda, which is passed a reference to a BreakTarget. This object defines a single method, break_with, which takes a value of type T and returns control flow to the site of the BreakTarget::deploy call, producing the value as the result. If the lambda exits normally, it must also produce a value of type T, which is produced as the result of the BreakTarget::deploy call.

Important Notes

The nonlocal breaking is implemented using a panic to unwind the stack. Any open Mutexes which are closed by this unwinding will be poisoned, among with other unwinding specific effects.

If panic = "abort" is enabled, calls to break_with will abort the program

Examples

use breaktarget::Breaktarget;

let result = BreakTarget::deploy(|target| {
    // ... Some logic here
    target.break_with(10i32);
    // ... Some logic here
});
assert_eq!(result, 10i32);
use breaktarget::BreakTarget;

fn some_function(target: &BreakTarget<i32>, cond: bool) {
   if cond {
       target.break_with(10);
   }
}

let result1 = BreakTarget::deploy(|target| {
    some_function(target, false);
    20
});
assert_eq!(result1, 20);

let result2 = BreakTarget::deploy(|target| {
    some_function(target, true);
    20
});
assert_eq!(result2, 10);