diagnostics_log_encoding::encode

Trait MutableBuffer

Source
pub trait MutableBuffer {
    // Required methods
    fn capacity(&self) -> usize;
    fn cursor(&self) -> usize;
    unsafe fn advance_cursor(&mut self, n: usize);
    unsafe fn put_slice_at(&mut self, src: &[u8], offset: usize);
    fn has_remaining(&self, num_bytes: usize) -> bool;

    // Provided methods
    fn put_slot(&mut self, width: usize) -> Result<WriteSlot, EncodingError> { ... }
    fn fill_slot(&mut self, slot: WriteSlot, src: &[u8]) { ... }
    fn put_slice(&mut self, src: &[u8]) -> Result<(), EncodingError> { ... }
    fn put_u64_le(&mut self, n: u64) -> Result<(), EncodingError> { ... }
    fn put_i64_le(&mut self, n: i64) -> Result<(), EncodingError> { ... }
    fn put_f64(&mut self, n: f64) -> Result<(), EncodingError> { ... }
}
Expand description

Analogous to bytes::BufMut with some additions to be able to write at specific offsets.

Required Methods§

Source

fn capacity(&self) -> usize

Returns the number of total bytes this container can store. Shared memory buffers are not expected to resize and this should return the same value during the entire lifetime of the buffer.

Source

fn cursor(&self) -> usize

Returns the current position into which the next write is expected.

Source

unsafe fn advance_cursor(&mut self, n: usize)

Advance the write cursor by n bytes.

§Safety

This is marked unsafe because a malformed caller may cause a subsequent out-of-bounds write.

Source

unsafe fn put_slice_at(&mut self, src: &[u8], offset: usize)

Write a copy of the src slice into the buffer, starting at the provided offset.

§Safety

Implementations are not expected to bounds check the requested copy, although they may do so and still satisfy this trait’s contract.

Source

fn has_remaining(&self, num_bytes: usize) -> bool

Returns whether the buffer has sufficient remaining capacity to write an incoming value.

Provided Methods§

Source

fn put_slot(&mut self, width: usize) -> Result<WriteSlot, EncodingError>

Advances the write cursor without immediately writing any bytes to the buffer. The returned struct offers the ability to later write to the provided portion of the buffer.

Source

fn fill_slot(&mut self, slot: WriteSlot, src: &[u8])

Write src into the provided slot that was created at a previous point in the stream.

Source

fn put_slice(&mut self, src: &[u8]) -> Result<(), EncodingError>

Writes the contents of the src buffer to self, starting at self.cursor() and advancing the cursor by src.len().

§Panics

This function panics if there is not enough remaining capacity in self.

Source

fn put_u64_le(&mut self, n: u64) -> Result<(), EncodingError>

Writes an unsigned 64 bit integer to self in little-endian byte order.

Advances the cursor by 8 bytes.

§Examples
use bytes::BufMut;

let mut buf = vec![0; 8];
buf.put_u64_le_at(0x0102030405060708, 0);
assert_eq!(buf, b"\x08\x07\x06\x05\x04\x03\x02\x01");
§Panics

This function panics if there is not enough remaining capacity in self.

Source

fn put_i64_le(&mut self, n: i64) -> Result<(), EncodingError>

Writes a signed 64 bit integer to self in little-endian byte order.

The cursor position is advanced by 8.

§Examples
use bytes::BufMut;

let mut buf = vec![0; 8];
buf.put_i64_le_at(0x0102030405060708, 0);
assert_eq!(buf, b"\x08\x07\x06\x05\x04\x03\x02\x01");
§Panics

This function panics if there is not enough remaining capacity in self.

Source

fn put_f64(&mut self, n: f64) -> Result<(), EncodingError>

Writes a double-precision IEEE 754 floating point number to self.

The cursor position is advanced by 8.

§Examples
use bytes::BufMut;

let mut buf = vec![];
buf.put_i64_le(0x0102030405060708);
assert_eq!(buf, b"\x08\x07\x06\x05\x04\x03\x02\x01");
§Panics

This function panics if there is not enough remaining capacity in self.

Implementations on Foreign Types§

Source§

impl MutableBuffer for Cursor<&mut [u8]>

Source§

fn has_remaining(&self, num_bytes: usize) -> bool

Source§

fn capacity(&self) -> usize

Source§

fn cursor(&self) -> usize

Source§

unsafe fn advance_cursor(&mut self, n: usize)

Source§

unsafe fn put_slice_at(&mut self, to_put: &[u8], offset: usize)

Source§

impl MutableBuffer for Cursor<Vec<u8>>

Source§

fn has_remaining(&self, num_bytes: usize) -> bool

Source§

fn capacity(&self) -> usize

Source§

fn cursor(&self) -> usize

Source§

unsafe fn advance_cursor(&mut self, n: usize)

Source§

unsafe fn put_slice_at(&mut self, to_put: &[u8], offset: usize)

Source§

impl MutableBuffer for Cursor<ResizableBuffer>

Source§

fn capacity(&self) -> usize

Source§

fn cursor(&self) -> usize

Source§

fn has_remaining(&self, _num_bytes: usize) -> bool

Source§

unsafe fn advance_cursor(&mut self, n: usize)

Source§

unsafe fn put_slice_at(&mut self, to_put: &[u8], offset: usize)

Source§

impl<T: MutableBuffer + ?Sized> MutableBuffer for &mut T

Source§

fn has_remaining(&self, num_bytes: usize) -> bool

Source§

fn capacity(&self) -> usize

Source§

fn cursor(&self) -> usize

Source§

unsafe fn advance_cursor(&mut self, n: usize)

Source§

unsafe fn put_slice_at(&mut self, to_put: &[u8], offset: usize)

Source§

impl<T: MutableBuffer + ?Sized> MutableBuffer for Box<T>

Source§

fn has_remaining(&self, num_bytes: usize) -> bool

Source§

fn capacity(&self) -> usize

Source§

fn cursor(&self) -> usize

Source§

unsafe fn advance_cursor(&mut self, n: usize)

Source§

unsafe fn put_slice_at(&mut self, to_put: &[u8], offset: usize)

Source§

impl<const N: usize> MutableBuffer for Cursor<[u8; N]>

Source§

fn has_remaining(&self, num_bytes: usize) -> bool

Source§

fn capacity(&self) -> usize

Source§

fn cursor(&self) -> usize

Source§

unsafe fn advance_cursor(&mut self, n: usize)

Source§

unsafe fn put_slice_at(&mut self, to_put: &[u8], offset: usize)

Implementors§