async-std/docs/src/patterns/small-patterns.md
2019-08-12 22:23:42 +02:00

385 B

Small Patterns

A collection of small, useful patterns.

Splitting streams

async-std doesn't provide a split() method on io handles. Instead, splitting a stream into a read and write half can be done like this:

use async_std::io;

async fn echo(stream: io::TcpStream) {
    let (reader, writer) = &mut (&stream, &stream);
    io::copy(reader, writer).await?;
}