File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change 1
1
use std:: io:: Read ;
2
2
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
+ /// ```
3
24
pub struct MultiReader < R > {
4
25
readers : Vec < R > ,
26
+ /// Points to where we read right now.
5
27
pos : usize ,
6
28
}
7
29
8
30
impl < R : Read > MultiReader < R > {
31
+ /// Creates `MultiReader`. `pos` is set to 0 by default.
9
32
pub fn new ( readers : Vec < R > ) -> Self {
10
33
Self { readers, pos : 0 }
11
34
}
You can’t perform that action at this time.
0 commit comments