1#[cfg(feature = "std")]
2use musli::{Buf, Context};
3
4pub struct Wrap<T> {
11 #[cfg_attr(not(feature = "std"), allow(unused))]
12 inner: T,
13}
14
15pub fn wrap<T>(inner: T) -> Wrap<T> {
20 Wrap { inner }
21}
22
23#[cfg(feature = "std")]
24impl<W> crate::writer::Writer for Wrap<W>
25where
26 W: std::io::Write,
27{
28 type Mut<'this> = &'this mut Self where Self: 'this;
29
30 #[inline]
31 fn borrow_mut(&mut self) -> Self::Mut<'_> {
32 self
33 }
34
35 #[inline]
36 fn write_buffer<C, B>(&mut self, cx: &C, buffer: B) -> Result<(), C::Error>
37 where
38 C: ?Sized + Context,
39 B: Buf,
40 {
41 self.write_bytes(cx, buffer.as_slice())
43 }
44
45 #[inline]
46 fn write_bytes<C>(&mut self, cx: &C, bytes: &[u8]) -> Result<(), C::Error>
47 where
48 C: ?Sized + Context,
49 {
50 self.inner.write_all(bytes).map_err(cx.map())?;
51 cx.advance(bytes.len());
52 Ok(())
53 }
54}