/rust/registry/src/index.crates.io-1949cf8c6b5b557f/nu-ansi-term-0.50.3/src/write.rs
Line | Count | Source |
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 | 0 | fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<(), Self::Error> { |
17 | 0 | fmt::Write::write_fmt(self, fmt) |
18 | 0 | } |
19 | | |
20 | 0 | fn write_str(&mut self, s: &Self::Wstr) -> Result<(), Self::Error> { |
21 | 0 | fmt::Write::write_str(self, s) |
22 | 0 | } |
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 | 0 | fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<(), Self::Error> { |
31 | 0 | std::io::Write::write_fmt(self, fmt) |
32 | 0 | } |
33 | | |
34 | 0 | fn write_str(&mut self, s: &Self::Wstr) -> Result<(), Self::Error> { |
35 | 0 | std::io::Write::write_all(self, s) |
36 | 0 | } |
37 | | } |