1#[cfg(feature = "alloc")]
4use alloc::vec::Vec;
5use core::fmt::{Debug, Display};
6
7pub trait Write {
9 type Error: Debug + Display;
10
11 fn write(&mut self, data: &[u8]) -> Result<(), Self::Error>;
13}
14
15impl<W: Write + ?Sized> Write for &'_ mut W {
16 type Error = W::Error;
17
18 fn write(&mut self, data: &[u8]) -> Result<(), Self::Error> {
19 (**self).write(data)
20 }
21}
22
23#[cfg(feature = "alloc")]
24impl Write for Vec<u8> {
25 type Error = core::convert::Infallible;
26
27 fn write(&mut self, data: &[u8]) -> Result<(), Self::Error> {
28 self.extend(data);
29 Ok(())
30 }
31}