Small Patterns

小而有用的模式的集合。

Splitting streams

async-std没有提供split()方法开启io处理。相反,可以将流分成读写部分,如下所示:

  1. # extern crate async_std;
  2. use async_std::{io, net::TcpStream};
  3. async fn echo(stream: TcpStream) {
  4. let (reader, writer) = &mut (&stream, &stream);
  5. io::copy(reader, writer).await;
  6. }