Crates.io | switcheroo |
lib.rs | switcheroo |
version | 0.2.9 |
source | src |
created_at | 2020-09-04 15:37:31.731533 |
updated_at | 2021-05-07 07:42:34.710185 |
description | Lightweight userland context switches |
homepage | |
repository | https://github.com/bkolobara/async-wormhole/tree/master/switcheroo |
max_upload_size | |
id | 284788 |
size | 65,284 |
This library is heavily inspired by https://github.com/edef1c/libfringe.
Currently only works in Rust nightly.
Switcheroo provides lightweight context switches in Rust. It runs on Windows, MacOs and Linux (x64 & AArch64).
use switcheroo::stack::*;
use switcheroo::Generator;
fn main() {
let stack = EightMbStack::new().unwrap();
let mut add_one = Generator::new(stack, |yielder, mut input| {
loop {
if input == 0 {
break;
}
input = yielder.suspend(input + 1);
}
});
assert_eq!(add_one.resume(2), Some(3));
assert_eq!(add_one.resume(127), Some(128));
assert_eq!(add_one.resume(0), None);
assert_eq!(add_one.resume(0), None);
}
On my Macbook Pro 15" (Late 2013) each context switch is comparable to a function call (sub-nanosecond).
Switcheroo tries hard to not let the context switching disturb default Rust behaviour on panics and unwinds. The displayed backtrace should stretch across the context switch boundary.
When dropping a non-empty stack, it will be unwind to free any resources allocated on it.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.