pub struct SliceWriter<'a> { /* private fields */ }Expand description
A Writer over a caller-owned slice. Never allocates.
Implementations§
Source§impl<'a> SliceWriter<'a>
impl<'a> SliceWriter<'a>
Sourcepub fn truncate(&mut self, at: usize) -> Result<()>
pub fn truncate(&mut self, at: usize) -> Result<()>
Discard everything written after at.
For an encoder that starts a value and then learns it cannot finish it — a store that writes half an attribute and then reports a hardware fault, say. Without this, the half-written bytes stay in the buffer in front of the error that replaces them, and the result is a response whose length agrees with nothing.
Only ever shrinks: at beyond what has been written is refused rather than
treated as an extension into whatever the buffer happened to contain.
§Errors
ErrorKind::InvalidLength when at is past the current position.
Trait Implementations§
Source§impl<'a> Debug for SliceWriter<'a>
impl<'a> Debug for SliceWriter<'a>
Source§impl Writer for SliceWriter<'_>
impl Writer for SliceWriter<'_>
Source§fn written(&self) -> usize
fn written(&self) -> usize
How many bytes have been written so far, for error offsets and for sizing a
length prefix against a
CountingWriter.Auto Trait Implementations§
impl<'a> !UnwindSafe for SliceWriter<'a>
impl<'a> Forget for SliceWriter<'a>
impl<'a> Freeze for SliceWriter<'a>
impl<'a> Move for SliceWriter<'a>
impl<'a> RefUnwindSafe for SliceWriter<'a>
impl<'a> Send for SliceWriter<'a>
impl<'a> Sync for SliceWriter<'a>
impl<'a> Unpin for SliceWriter<'a>
impl<'a> UnsafeUnpin for SliceWriter<'a>where
&'a mut [u8]: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more