3 个稳定版本

1.0.2 2024年7月28日

#456并发

Download history · Rust 包仓库 342/week @ 2024-07-25 · Rust 包仓库 40/week @ 2024-08-01 · Rust 包仓库

382 每月下载量

MIT 许可证

8KB
76 代码行

tokio-bichannel

tokio::sync::mpsc 通道的包装器,以提供简单的双向流 API。

我该如何安装这个crate?

将以下内容添加到您的 Cargo.toml 文件中

tokio-bichannel = "1"

示例

#[tokio::test]
async fn main() {
    let (mut chan1, mut chan2) = channel::<String, String>(10);

    chan1.send("Hello from chan1".to_string()).await.unwrap();
    chan2.send("Hello from chan2".to_string()).await.unwrap();

    let msg1 = chan2.recv().await.unwrap();
    let msg2 = chan1.recv().await.unwrap();

    assert_eq!(msg1, "Hello from chan1");
    assert_eq!(msg2, "Hello from chan2");
}

依赖项

~2–3MB
~46K SLoC