https://github.com/mpdn/rye
A tiny experiment into building safe fibers in Rust
https://github.com/mpdn/rye
Last synced: 12 months ago
JSON representation
A tiny experiment into building safe fibers in Rust
- Host: GitHub
- URL: https://github.com/mpdn/rye
- Owner: mpdn
- Created: 2020-10-14T18:08:27.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-10-16T19:15:46.000Z (over 5 years ago)
- Last Synced: 2025-05-08T01:44:49.339Z (about 1 year ago)
- Language: Rust
- Homepage:
- Size: 4.88 KB
- Stars: 26
- Watchers: 5
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# rye
Rye is a minimal, x86-64-only experiment into adding fibers to Rust.
Rye exposes an API that allows spawning, scheduling, and deallocating fibers. This API, while
largely safe, rests on a lot of unsafe assumptions not necessarily guaranteed by the rust
compiler. This is just an experiment and you should not use it for anything critical.
Rye has no central place where fibers are registered. Instead, when a fiber is yielded to it
receives a handle to the yielding fiber.
## Example
```rust
use rye::{Fiber, AllocStack};
// Create the fiber
let (stack, fiber) = Fiber::spawn(AllocStack::new(4096), |main| {
println!("Hello from fiber!");
main.yield_to();
});
// Yield to the fiber and return. This prints:
// Hello from main!
// Hello from fiber!
// Back to main!
println!("Hello from main!");
let fiber = fiber.yield_to();
println!("Back to main!");
// Reclaim stack to deallocate fiber
stack.reclaim(fiber);
```