write.rs 917 B

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