nu_ansi_term/
write.rs

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