summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarsha <[email protected]>2023-05-24 23:05:18 -0700
committerGitHub <[email protected]>2023-05-25 14:05:18 +0800
commit60b452951db5887e5226b1e20c8f9f70a7db576b (patch)
tree9e39db87eb89767861aff95bf141358cb34b83d3
parent73421a20b69f3a6c4e6ab3e6531027850bc70e69 (diff)
Minor documentation edit for prefixedIO (#169)
-rw-r--r--monoio/src/io/util/prefixed_io.rs25
1 files changed, 24 insertions, 1 deletions
diff --git a/monoio/src/io/util/prefixed_io.rs b/monoio/src/io/util/prefixed_io.rs
index 26dd1c8..f523a4e 100644
--- a/monoio/src/io/util/prefixed_io.rs
+++ b/monoio/src/io/util/prefixed_io.rs
@@ -4,7 +4,30 @@ use crate::{
io::{AsyncReadRent, AsyncWriteRent, CancelableAsyncReadRent, CancelableAsyncWriteRent},
};
-/// Wrapped IO with given read prefix.
+/// PrefixedReadIO facilitates the addition of a prefix to an IO stream,
+/// enabling stream rewinding and peeking capabilities.
+/// Subsequent reads will preserve access to the original stream contents.
+/// ```
+/// # use monoio::io::PrefixedReadIo;
+/// # use monoio::io::{AsyncReadRent, AsyncWriteRent, AsyncReadRentExt};
+///
+/// async fn demo<T>(mut stream: T)
+/// where
+/// T: AsyncReadRent + AsyncWriteRent,
+/// {
+/// // let stream = b"hello world";
+/// let buf = vec![0 as u8; 6];
+/// let (_, buf) = stream.read_exact(buf).await;
+/// assert_eq!(buf, b"hello ");
+///
+/// let prefix_buf = std::io::Cursor::new(buf);
+/// let mut pio = PrefixedReadIo::new(stream, prefix_buf);
+///
+/// let buf = vec![0 as u8; 11];
+/// let (_, buf) = pio.read_exact(buf).await;
+/// assert_eq!(buf, b"hello world");
+/// }
+/// ```
pub struct PrefixedReadIo<I, P> {
io: I,
prefix: P,