1 use std::fmt;
2 use std::io;
3 
4 
5 pub trait AnyWrite {
6     type wstr: ?Sized;
7     type Error;
8 
write_fmt(&mut self, fmt: fmt::Arguments) -> Result<(), Self::Error>9     fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<(), Self::Error>;
10 
write_str(&mut self, s: &Self::wstr) -> Result<(), Self::Error>11     fn write_str(&mut self, s: &Self::wstr) -> Result<(), Self::Error>;
12 }
13 
14 
15 impl<'a> AnyWrite for fmt::Write + 'a {
16     type wstr = str;
17     type Error = fmt::Error;
18 
write_fmt(&mut self, fmt: fmt::Arguments) -> Result<(), Self::Error>19     fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<(), Self::Error> {
20         fmt::Write::write_fmt(self, fmt)
21     }
22 
write_str(&mut self, s: &Self::wstr) -> Result<(), Self::Error>23     fn write_str(&mut self, s: &Self::wstr) -> Result<(), Self::Error> {
24         fmt::Write::write_str(self, s)
25     }
26 }
27 
28 
29 impl<'a> AnyWrite for io::Write + 'a {
30     type wstr = [u8];
31     type Error = io::Error;
32 
write_fmt(&mut self, fmt: fmt::Arguments) -> Result<(), Self::Error>33     fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<(), Self::Error> {
34         io::Write::write_fmt(self, fmt)
35     }
36 
write_str(&mut self, s: &Self::wstr) -> Result<(), Self::Error>37     fn write_str(&mut self, s: &Self::wstr) -> Result<(), Self::Error> {
38         io::Write::write_all(self, s)
39     }
40 }
41