File tree 2 files changed +54
-0
lines changed
2 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -32,3 +32,6 @@ path = "src/3_9_5/main.rs"
32
32
[[bin ]]
33
33
name = " 3_6_1"
34
34
path = " src/3_6_1/main.rs"
35
+ [[bin ]]
36
+ name = " 3_7"
37
+ path = " src/3_7/main.rs"
Original file line number Diff line number Diff line change
1
+ use std:: io:: { Read , Write } ;
2
+
3
+ struct MultiReader ( Vec < Box < dyn Read > > ) ;
4
+
5
+ impl MultiReader {
6
+ pub fn new ( readers : Vec < Box < dyn Read > > ) -> Self {
7
+ Self ( readers)
8
+ }
9
+ }
10
+
11
+ impl Read for MultiReader {
12
+ fn read ( & mut self , buf : & mut [ u8 ] ) -> std:: io:: Result < usize > {
13
+ for r in & mut self . 0 {
14
+ r. read_exact ( buf) ?;
15
+ }
16
+ Ok ( buf. len ( ) )
17
+ }
18
+ }
19
+
20
+ struct TeeReader < R , W >
21
+ where
22
+ R : Read ,
23
+ W : Write ,
24
+ {
25
+ reader : R ,
26
+ writer : W ,
27
+ }
28
+
29
+ impl < R , W > TeeReader < R , W >
30
+ where
31
+ R : Read ,
32
+ W : Write ,
33
+ {
34
+ pub fn new ( reader : R , writer : W ) -> Self {
35
+ Self { reader, writer }
36
+ }
37
+ }
38
+
39
+ impl < R , W > Read for TeeReader < R , W >
40
+ where
41
+ R : Read ,
42
+ W : Write ,
43
+ {
44
+ fn read ( & mut self , buf : & mut [ u8 ] ) -> std:: io:: Result < usize > {
45
+ let n = self . reader . read ( buf) ?;
46
+ self . writer . write_all ( & buf[ ..n] ) ?;
47
+ Ok ( n)
48
+ }
49
+ }
50
+
51
+ fn main ( ) { }
You can’t perform that action at this time.
0 commit comments