Debian Codegraph @

debian/rust-vendor/nu-ansi-term/src/write.rs

raw
1 use core::fmt;
2
3 pub 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
12 impl<'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")]
26 impl<'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 }