1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#![deny(missing_docs)]
#![forbid(unsafe_code)]
use std::io::{Read, Result, Write};
pub struct ReadWrite<R: Read, W: Write>(pub R, pub W);
impl<R: Read, W: Write> From<(R, W)> for ReadWrite<R, W> {
fn from((r, w): (R, W)) -> Self {
ReadWrite(r, w)
}
}
impl<R: Read, W: Write> ReadWrite<R, W> {
pub fn new(r: R, w: W) -> Self {
ReadWrite(r, w)
}
pub fn borrow(&self) -> (&R, &W) {
(&self.0, &self.1)
}
pub fn borrow_read(&self) -> &R {
&self.0
}
pub fn borrow_write(&self) -> &W {
&self.1
}
pub fn borrow_mut(&mut self) -> (&mut R, &mut W) {
(&mut self.0, &mut self.1)
}
pub fn borrow_mut_read(&mut self) -> &mut R {
&mut self.0
}
pub fn borrow_mut_write(&mut self) -> &mut W {
&mut self.1
}
pub fn into_inner(self) -> (R, W) {
(self.0, self.1)
}
pub fn into_reader(self) -> R {
self.0
}
pub fn into_writer(self) -> W {
self.1
}
}
impl<R: Read, W: Write> Read for ReadWrite<R, W> {
fn read(&mut self, buf:&mut [u8]) -> Result<usize> {
self.0.read(buf)
}
}
impl<R: Read, W: Write> Write for ReadWrite<R, W> {
fn write(&mut self, buf:&[u8]) -> Result<usize> {
self.1.write(buf)
}
fn flush(&mut self,) -> Result<()> {
self.1.flush()
}
}