diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2023-04-11 15:58:08 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2023-04-11 15:58:08 +0900 |
commit | 33dbf2a980f7fd9cb3a1a262099e423fd99faa59 (patch) | |
tree | d127c25c6346a8c13375f12e61e026bccf4b1496 /src/write.rs | |
download | rust-ansi_term-33dbf2a980f7fd9cb3a1a262099e423fd99faa59.tar.gz rust-ansi_term-33dbf2a980f7fd9cb3a1a262099e423fd99faa59.tar.bz2 rust-ansi_term-33dbf2a980f7fd9cb3a1a262099e423fd99faa59.zip |
Import ansi_term 0.12.1upstream/0.12.1upstream
Diffstat (limited to 'src/write.rs')
-rw-r--r-- | src/write.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/write.rs b/src/write.rs new file mode 100644 index 0000000..65a64fe --- /dev/null +++ b/src/write.rs @@ -0,0 +1,40 @@ +use std::fmt; +use std::io; + + +pub trait AnyWrite { + type wstr: ?Sized; + type Error; + + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<(), Self::Error>; + + fn write_str(&mut self, s: &Self::wstr) -> Result<(), Self::Error>; +} + + +impl<'a> AnyWrite for fmt::Write + 'a { + type wstr = str; + type Error = fmt::Error; + + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<(), Self::Error> { + fmt::Write::write_fmt(self, fmt) + } + + fn write_str(&mut self, s: &Self::wstr) -> Result<(), Self::Error> { + fmt::Write::write_str(self, s) + } +} + + +impl<'a> AnyWrite for io::Write + 'a { + type wstr = [u8]; + type Error = io::Error; + + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<(), Self::Error> { + io::Write::write_fmt(self, fmt) + } + + fn write_str(&mut self, s: &Self::wstr) -> Result<(), Self::Error> { + io::Write::write_all(self, s) + } +} |