2
0
Fork 1
mirror of https://github.com/async-rs/async-std.git synced 2025-04-23 16:56:46 +00:00
async-std/docs/src/patterns/small-patterns.md
2019-08-12 21:17:21 +02:00

18 lines
No EOL
399 B
Markdown

# Small Patterns
A collection of small, useful patterns.
<!-- toc -->
## 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:
```rust
use async_std::io;
async fn echo(stream: io::TcpStream) {
let (reader, writer) = &mut (&stream, &stream);
io::copy(reader, writer).await?;
}
```