Skip to content

Commit 6722774

Browse files
committed
add docs
1 parent 68e2d64 commit 6722774

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

lib/src/io/multi_reader.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,34 @@
11
use std::io::Read;
22

3+
/// Takes multiple `std::io::Read` at once.
4+
/// This is inspired by `io.MultiReader` in Go.
5+
///
6+
/// # Example
7+
///
8+
/// ```
9+
/// use std::{
10+
/// io::{copy, stdout, Read},
11+
/// usize,
12+
/// };
13+
/// use lib::io::MultiReader;
14+
///
15+
/// fn main() -> std::io::Result<()> {
16+
/// let header = "---- HEADER ----\n".as_bytes();
17+
/// let content = "Example of MultiReader\n".as_bytes();
18+
/// let footer = "---- FOOTER ----\n".as_bytes();
19+
/// let mut multi_reader = MultiReader::new(vec![header, content, footer]);
20+
/// copy(&mut multi_reader, &mut stdout())?;
21+
/// Ok(())
22+
/// }
23+
/// ```
324
pub struct MultiReader<R> {
425
readers: Vec<R>,
26+
/// Points to where we read right now.
527
pos: usize,
628
}
729

830
impl<R: Read> MultiReader<R> {
31+
/// Creates `MultiReader`. `pos` is set to 0 by default.
932
pub fn new(readers: Vec<R>) -> Self {
1033
Self { readers, pos: 0 }
1134
}

0 commit comments

Comments
 (0)