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