每个核心一个线程的异步 Rust 运行时,支持 IOCP/io_uring/polling。
--- # Compio 一个基于 IOCP/io_uring/polling 的每核一个线程的 Rust 运行时,灵感来自 monoio。 ## 快速入门 将 compio 添加为依赖项: bash cargo add compio --features macros,fs 然后使用提供的高级 API 执行文件系统和网络 IO: ```rust
use compio::{fs::File, io::AsyncReadAtExt};
#[compio::main]
async fn main() {
let file = File::open("Cargo.toml").await.unwrap();
let (read, buffer) = file.read_to_end_at(Vec::with_capacity(1024), 0).await.unwrap();
assert_eq!(read, buffer.len());
let buffer = String::from_utf8(buffer).unwrap();
println!("{}", buffer);
}
也可以手动使用低级驱动(无异步执行器的主动程序)。请参阅 [`driver` 示例](./compio/examples/driver.rs)。 ## 可观察性 `console` 功能使运行时发出 [`tracing`] 跨程序和事件, `tokio-console` 可以消费这些信息,因此可以使用 `compio` 应用程序进行检查:bash
cargo add compio --features console
cargo add console-subscriber
toml
console-subscriber refuses to run unless the runtime is known to berustflags = ["--cfg", "console_without_tokio_unstable"]
rust
console_subscriber::init();
compio::runtime::Runtime::new().unwrap().block_on(async {
// ...
});
然后运行 `tokio-console` 以监视任务、轮询时间和唤醒器活动。[`console` 模块文档](https://docs.rs/compio-runtime/latest/compio_runtime/console/) 说明了哪些内容会被报告,哪些内容不会被报告。[`console` 示例](./compio/examples/console.rs) 在分派器上运行一个回显服务器,这样控制台可以显示每个核心线程的任务,并显示在它发出警告的错误任务旁边。它会在命令行上传递 cfg:
[build]
[`tracing`]: https://docs.rs/tracing
[`tokio-console`]: https://github.com/tokio-rs/console暂无开放 Issues,或尚未同步最近议题。