@@ -6,36 +6,34 @@ use std::{collections::VecDeque, io::Read};
66/// # Example
77///
88/// ```
9- /// use std::{
10- /// collections::VecDeque,
11- /// io::{copy, stdout, Read},
12- /// };
9+ /// use std::io::{copy, stdout};
1310/// use lib::io::MultiReader;
1411///
1512/// fn main() -> std::io::Result<()> {
1613/// let header = "---- HEADER ----\n".as_bytes();
1714/// let content = "Example of MultiReader\n".as_bytes();
1815/// let footer = "---- FOOTER ----\n".as_bytes();
19- /// let mut multi_reader = MultiReader::new(VecDeque::from(vec![
20- /// Box::new(header) as Box<dyn Read>,
21- /// Box::new(content) as Box<dyn Read>,
22- /// Box::new(footer) as Box<dyn Read>,
23- /// ]));
16+ /// let mut multi_reader =
17+ /// MultiReader::new(vec![Box::new(header), Box::new(content), Box::new(footer)]);
2418/// copy(&mut multi_reader, &mut stdout())?;
2519/// Ok(())
2620/// }
2721/// ```
2822pub struct MultiReader {
2923 readers : VecDeque < Box < dyn Read > > ,
30- /// Points to where we read right now .
24+ /// Points to current element while reading .
3125 current : Option < Box < dyn Read > > ,
3226}
3327
3428impl MultiReader {
35- /// Creates `MultiReader`. `pos` is set to 0 by default.
36- pub fn new ( mut readers : VecDeque < Box < dyn Read > > ) -> Self {
37- let current = readers. pop_front ( ) ;
38- Self { readers, current }
29+ /// Constructs `MultiReader`. `current` is set to the first element that is popped out from `VecDeque`.
30+ pub fn new ( readers : Vec < Box < dyn Read > > ) -> Self {
31+ let mut deque = VecDeque :: from ( readers) ;
32+ let current = deque. pop_front ( ) ;
33+ Self {
34+ readers : deque,
35+ current,
36+ }
3937 }
4038}
4139
0 commit comments