use crate::read_write::Write;
use alloc::vec::Vec;
use void::Void;
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc", feature = "std"))))]
pub struct VecWriter(Vec<u8>);
impl VecWriter {
#[inline(always)]
#[must_use]
pub fn with_capacity(capacity: usize) -> VecWriter {
VecWriter(Vec::with_capacity(capacity))
}
}
impl Write for VecWriter {
type Output = Vec<u8>;
type Error = Void;
#[inline(always)]
fn write(&mut self, data: u8) -> Result<(), Self::Error> {
self.0.push(data);
Ok(())
}
#[inline(always)]
fn finish(self) -> Result<Self::Output, Self::Error> {
Ok(self.0)
}
}