#[cfg(feature = "std")]
use musli::context::Buffer;
#[cfg(feature = "std")]
use musli::Context;
pub struct Wrap<T> {
#[cfg_attr(not(feature = "std"), allow(unused))]
inner: T,
}
pub fn wrap<T>(inner: T) -> Wrap<T> {
Wrap { inner }
}
#[cfg(feature = "std")]
impl<W> crate::writer::Writer for Wrap<W>
where
W: std::io::Write,
{
type Error = std::io::Error;
type Mut<'this> = &'this mut Self where Self: 'this;
#[inline]
fn borrow_mut(&mut self) -> Self::Mut<'_> {
self
}
#[inline]
fn write_buffer<C, B>(&mut self, cx: &mut C, buffer: B) -> Result<(), C::Error>
where
C: Context<Input = Self::Error>,
B: Buffer,
{
self.write_bytes(cx, unsafe { buffer.as_slice() })
}
#[inline]
fn write_bytes<C>(&mut self, cx: &mut C, bytes: &[u8]) -> Result<(), C::Error>
where
C: Context<Input = Self::Error>,
{
self.inner.write_all(bytes).map_err(|err| cx.report(err))?;
cx.advance(bytes.len());
Ok(())
}
}