1use futures::{Async, Poll};
2use std::{fmt, io};
3use {AsyncRead, AsyncWrite};
4
5#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
16pub struct AllowStdIo<T>(T);
17
18impl<T> AllowStdIo<T> {
19 pub fn new(io: T) -> Self {
21 AllowStdIo(io)
22 }
23
24 pub fn get_ref(&self) -> &T {
26 &self.0
27 }
28
29 pub fn get_mut(&mut self) -> &mut T {
31 &mut self.0
32 }
33
34 pub fn into_inner(self) -> T {
36 self.0
37 }
38}
39
40impl<T> io::Write for AllowStdIo<T>
41where
42 T: io::Write,
43{
44 fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
45 self.0.write(buf)
46 }
47 fn flush(&mut self) -> io::Result<()> {
48 self.0.flush()
49 }
50 fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
51 self.0.write_all(buf)
52 }
53 fn write_fmt(&mut self, fmt: fmt::Arguments) -> io::Result<()> {
54 self.0.write_fmt(fmt)
55 }
56}
57
58impl<T> AsyncWrite for AllowStdIo<T>
59where
60 T: io::Write,
61{
62 fn shutdown(&mut self) -> Poll<(), io::Error> {
63 Ok(Async::Ready(()))
64 }
65}
66
67impl<T> io::Read for AllowStdIo<T>
68where
69 T: io::Read,
70{
71 fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
72 self.0.read(buf)
73 }
74 fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
77 self.0.read_to_end(buf)
78 }
79 fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
80 self.0.read_to_string(buf)
81 }
82 fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
83 self.0.read_exact(buf)
84 }
85}
86
87impl<T> AsyncRead for AllowStdIo<T>
88where
89 T: io::Read,
90{
91 }