Crates.io | may |
lib.rs | may |
version | |
source | src |
created_at | 2017-12-22 07:58:36.459385 |
updated_at | 2024-10-26 11:22:02.105779 |
description | Rust Stackful Coroutine Library |
homepage | https://github.com/Xudong-Huang/may.git |
repository | https://github.com/Xudong-Huang/may.git |
max_upload_size | |
id | 43999 |
Cargo.toml error: | TOML parse error at line 25, column 1 | 25 | 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` |
size | 0 |
May is a high-performance library for programming stackful coroutines with which you can easily develop and maintain massive concurrent programs. It can be thought as the Rust version of the popular Goroutine.
A naive echo server implemented with May:
#[macro_use]
extern crate may;
use may::net::TcpListener;
use std::io::{Read, Write};
fn main() {
let listener = TcpListener::bind("127.0.0.1:8000").unwrap();
while let Ok((mut stream, _)) = listener.accept() {
go!(move || {
let mut buf = vec![0; 1024 * 16]; // alloc in heap!
while let Ok(n) = stream.read(&mut buf) {
if n == 0 {
break;
}
stream.write_all(&buf[0..n]).unwrap();
}
});
}
}
You can refer to https://tfb-status.techempower.com/ to get the latest may_minihttp comparisons with other most popular frameworks.
There is a detailed document that describes May's main restrictions. In general, there are four things you should follow when writing programs that use coroutines:
It's considered unsafe with the following pattern:
set_tls(); // Or another coroutine API that would cause scheduling: coroutine::yield_now(); use_tls();
but it's safe if your code is not sensitive about the previous state of TLS. Or there is no coroutines scheduling between set TLS and use TLS.
Note:
The first three rules are common when using cooperative asynchronous libraries in Rust. Even using a futures-based system also have these limitations. So what you should really focus on is a coroutine stack size, make sure it's big enough for your applications.
If you want to tune your coroutine stack size, please check out this document.
May is licensed under either of the following, at your option: