Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
Signed-off-by: Xuanwo <[email protected]>
  • Loading branch information
Xuanwo committed Mar 12, 2024
1 parent 4409085 commit 56f01dd
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions core/src/types/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,35 @@ use crate::*;
///
/// # Usage
///
/// Reader implements the following APIs:
/// [`Reader`] provides multiple ways to read data from given reader. Please note that it's
/// undefined behavior to use `Reader` in different ways.
///
/// - `AsyncRead`
/// - `AsyncSeek`
/// - `Stream<Item = <io::Result<Bytes>>>`
/// ## Direct
///
/// For reading data, we can use `AsyncRead` and `Stream`. The mainly
/// different is where the `copy` happens.
/// [`Reader`] provides public API including [`Reader::read`], [`Reader::seek`] and
/// [`Reader::read_to_end`]. You can use those APIs directly without extra copy.
///
/// `AsyncRead` requires user to prepare a buffer for `Reader` to fill.
/// And `Stream` will stream out a `Bytes` for user to decide when to copy
/// it's content.
/// ## Bytes Stream
///
/// For example, users may have their only CPU/IO bound workers and don't
/// want to do copy inside IO workers. They can use `Stream` to get a `Bytes`
/// and consume it in side CPU workers inside.
/// [`Reader`] can be used as `Stream<Item = <io::Result<Bytes>>>`.
///
/// Besides, `Stream` **COULD** reduce an extra copy if underlying reader is
/// stream based (like services s3, azure which based on HTTP).
/// It also implements [`Send`], [`Sync`] and [`Unpin`].
///
/// ## Futures AsyncRead
///
/// [`Reader`] can be used as [`futures::AsyncRead`] and [`futures::AsyncSeek`].
///
/// It also implements [`Send`], [`Sync`] and [`Unpin`].
///
/// [`Reader`] provides [`Reader::into_futures_read`] to remove extra APIs upon self.
///
/// ## Tokio AsyncRead
///
/// [`Reader`] can be used as [`tokio::io::AsyncRead`] and [`tokio::io::AsyncSeek`].
///
/// It also implements [`Send`], [`Sync`] and [`Unpin`].
///
/// [`Reader`] provides [`Reader::into_tokio_read`] to remove extra APIs upon self.
pub struct Reader {
state: State,
}
Expand Down

0 comments on commit 56f01dd

Please sign in to comment.