forked from mirror/async-std
Add small patterns library
parent
eadd3ed1f6
commit
6c7922a404
@ -1 +1,5 @@
|
||||
# Async Patterns
|
||||
# Patterns
|
||||
|
||||
This section documents small, useful patterns.
|
||||
|
||||
It is intended to be read at a glance, allowing you to get back when you have a problem.
|
@ -0,0 +1,18 @@
|
||||
# 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?;
|
||||
}
|
||||
```
|
Loading…
Reference in New Issue