Trait codec::buffer::BufferWriter [−][src]
A trait to provide sequential write over a fixed size or dynamic size memory buffer.
The memory buffer can be std::io::Cursor<AsRef<[u8]>>
or &mut [u8]
,
which is fixed sized, or Vec<u8>
, which is dynamically sized.
Required methods
unsafe fn bytes_mut(&mut self, size: usize) -> &mut [u8]
[src]
Returns a mutable slice starting at current position.
The caller may hint the underlying buffer to grow according to size
if the underlying buffer is dynamically sized (i.e. is capable to grow).
The size of the returned slice may be less than size
given. For example,
when underlying buffer is fixed sized and there is no enough space any more.
Safety
The returned mutable slice is for writing only and should be never used for
reading since it might contain uninitialized memory when underlying buffer
is dynamically sized. For this reason, this function is marked unsafe
.
unsafe fn advance_mut(&mut self, count: usize)
[src]
Advances the position of internal cursor for a previous write.
Safety
The caller should ensure that advanced positions have been all written
previously. If the cursor is moved beyond actually written data, it will
leave uninitialized memory. For this reason, this function is marked
unsafe
.
Panics
This function may panic in some implementors when remaining space is not large enough to advance.
TODO: We should make the panic behaviour deterministic.
fn write_bytes(&mut self, values: &[u8]) -> Result<()>
[src]
Writes all bytes and advances the position of internal cursor,
Errors
Returns Error::Io
if buffer remaining size < values.len().