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