Skip to content

Commit ba10875

Browse files
committed
Add docs
1 parent 8e19102 commit ba10875

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/lib.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
//! Creates an asynchronous piped reader and writer pair using `tokio.rs`.
2+
//!
3+
//! # Examples
4+
//!
5+
//! ```
6+
//! # async fn run() {
7+
//! use async_pipe;
8+
//! use tokio::prelude::*;
9+
//!
10+
//! let (mut w, mut r) = async_pipe::pipe();
11+
//!
12+
//! tokio::spawn(async move {
13+
//! w.write_all(b"hello world").await.unwrap();
14+
//! });
15+
//!
16+
//! let mut v = Vec::new();
17+
//! r.read_to_end(&mut v).await.unwrap();
18+
//!
19+
//! println!("Received: {:?}", String::from_utf8(v));
20+
//! # }
21+
//!
22+
//! tokio::runtime::Runtime::new().unwrap().block_on(run());
23+
//! ```
24+
125
use state::State;
226
use std::sync::{Arc, Mutex};
327

@@ -8,6 +32,7 @@ mod reader;
832
mod state;
933
mod writer;
1034

35+
/// Creates a piped pair of an [`AsyncWrite`](https://docs.rs/tokio/0.2.16/tokio/io/trait.AsyncWrite.html) and an [`AsyncRead`](https://docs.rs/tokio/0.2.15/tokio/io/trait.AsyncRead.html).
1136
pub fn pipe() -> (PipeWriter, PipeReader) {
1237
let shared_state = Arc::new(Mutex::new(State {
1338
reader_waker: None,

src/reader.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ use std::sync::{Arc, Mutex};
55
use std::task::{Context, Poll};
66
use tokio::io::{self, AsyncRead};
77

8+
/// The read half of the pipe which implements [`AsyncRead`](https://docs.rs/tokio/0.2.15/tokio/io/trait.AsyncRead.html).
89
pub struct PipeReader {
910
pub(crate) state: Arc<Mutex<State>>,
1011
}
1112

1213
impl PipeReader {
14+
/// Closes the pipe, any further read will return EOF and any further write will raise an error.
1315
pub fn close(&self) -> io::Result<()> {
1416
match self.state.lock() {
1517
Ok(mut state) => {

src/writer.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ use std::sync::{Arc, Mutex};
55
use std::task::{Context, Poll};
66
use tokio::io::{self, AsyncWrite};
77

8+
/// The write half of the pipe which implements [`AsyncWrite`](https://docs.rs/tokio/0.2.16/tokio/io/trait.AsyncWrite.html).
89
pub struct PipeWriter {
910
pub(crate) state: Arc<Mutex<State>>,
1011
}
1112

1213
impl PipeWriter {
14+
/// Closes the pipe, any further read will return EOF and any further write will raise an error.
1315
pub fn close(&self) -> io::Result<()> {
1416
match self.state.lock() {
1517
Ok(mut state) => {

0 commit comments

Comments
 (0)