| 1 | #![cfg(feature = "std")] |
| 2 | |
| 3 | use std::io::Write; |
| 4 | |
| 5 | use crate::bytestream::ZByteIoError; |
| 6 | |
| 7 | impl<T: Write> crate::bytestream::ZByteWriterTrait for T { |
| 8 | fn write_bytes(&mut self, buf: &[u8]) -> Result<usize, ZByteIoError> { |
| 9 | self.write(buf).map_err(ZByteIoError::StdIoError) |
| 10 | } |
| 11 | |
| 12 | fn write_all_bytes(&mut self, buf: &[u8]) -> Result<(), ZByteIoError> { |
| 13 | self.write_all(buf).map_err(ZByteIoError::StdIoError) |
| 14 | } |
| 15 | |
| 16 | fn write_const_bytes<const N: usize>(&mut self, buf: &[u8; N]) -> Result<(), ZByteIoError> { |
| 17 | self.write_all_bytes(buf) |
| 18 | } |
| 19 | fn flush_bytes(&mut self) -> Result<(), ZByteIoError> { |
| 20 | self.flush().map_err(ZByteIoError::StdIoError) |
| 21 | } |
| 22 | fn reserve_capacity(&mut self, _: usize) -> Result<(), ZByteIoError> { |
| 23 | // we can't reserve capacity, sorry to implementations where this |
| 24 | // matters |
| 25 | Ok(()) |
| 26 | } |
| 27 | } |