mirror of
https://github.com/async-rs/async-std.git
synced 2025-02-28 15:19:41 +00:00
Add small patterns library
This commit is contained in:
parent
eadd3ed1f6
commit
6c7922a404
3 changed files with 24 additions and 1 deletions
|
@ -17,6 +17,7 @@
|
||||||
- [Proper Shutdown](./patterns/proper-shutdown.md)
|
- [Proper Shutdown](./patterns/proper-shutdown.md)
|
||||||
- [Background Tasks](./patterns/background-tasks.md)
|
- [Background Tasks](./patterns/background-tasks.md)
|
||||||
- [Testing](./patterns/testing.md)
|
- [Testing](./patterns/testing.md)
|
||||||
|
- [Collected Small Patterns](./patters/small-patterns.md)
|
||||||
- [Security practices](./security/index.md)
|
- [Security practices](./security/index.md)
|
||||||
- [Security disclosures and policy](./security/policy.md)
|
- [Security disclosures and policy](./security/policy.md)
|
||||||
- [Glossary](./glossary.md)
|
- [Glossary](./glossary.md)
|
||||||
|
|
|
@ -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.
|
18
docs/src/patterns/small-patterns.md
Normal file
18
docs/src/patterns/small-patterns.md
Normal file
|
@ -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 a new issue