pub struct Buffer<'a> { /* private fields */ }
Implementations§
source§impl<'a> Buffer<'a>
impl<'a> Buffer<'a>
sourcepub fn flatten(&mut self) -> &mut EncoderBuffer<'a>
pub fn flatten(&mut self) -> &mut EncoderBuffer<'a>
Ensures an extra bytes are written into the main EncoderBuffer.
source§impl<'a> Buffer<'a>
impl<'a> Buffer<'a>
Implement a version with bytes
enabled
sourcepub fn new(inner: EncoderBuffer<'a>) -> Self
pub fn new(inner: EncoderBuffer<'a>) -> Self
Initializes a buffer without any extra bytes at the end
sourcepub fn new_with_extra(inner: EncoderBuffer<'a>, extra: Option<Bytes>) -> Self
pub fn new_with_extra(inner: EncoderBuffer<'a>, extra: Option<Bytes>) -> Self
Initializes the buffer with extra bytes
NOTE the EncoderBuffer position should not include the extra bytes. This ensures the bytes
can be “flushed” into the EncoderBuffer if another write happens or flatten
is called.
sourcepub fn into_inner(self) -> (EncoderBuffer<'a>, Option<Bytes>)
pub fn into_inner(self) -> (EncoderBuffer<'a>, Option<Bytes>)
Converts the buffer into its inner parts
NOTE: the EncoderBuffer position will not include the extra bytes. The caller will need to account for this data.
sourcepub fn inner_mut(&mut self) -> (&mut EncoderBuffer<'a>, &Option<Bytes>)
pub fn inner_mut(&mut self) -> (&mut EncoderBuffer<'a>, &Option<Bytes>)
Returns the inner EncoderBuffer, along with the current extra bytes
Trait Implementations§
source§impl<'a> Encoder for Buffer<'a>
impl<'a> Encoder for Buffer<'a>
source§const SPECIALIZES_BYTES: bool = true
const SPECIALIZES_BYTES: bool = true
We have special handling for writes that include Bytes
so signal that
source§fn write_sized<F: FnOnce(&mut [u8])>(&mut self, len: usize, write: F)
fn write_sized<F: FnOnce(&mut [u8])>(&mut self, len: usize, write: F)
Calls
write
with a slice of len
bytes at the current write positionsource§fn write_slice(&mut self, slice: &[u8])
fn write_slice(&mut self, slice: &[u8])
Copies the slice into the buffer
fn write_bytes(&mut self, bytes: Bytes)
source§fn write_zerocopy<T: AsBytes + FromBytes + Unaligned, F: FnOnce(&mut T)>(
&mut self,
write: F
)
fn write_zerocopy<T: AsBytes + FromBytes + Unaligned, F: FnOnce(&mut T)>( &mut self, write: F )
Writes a zerocopy value to the buffer
source§fn write_repeated(&mut self, count: usize, value: u8)
fn write_repeated(&mut self, count: usize, value: u8)
source§fn encode<T: EncoderValue>(&mut self, value: &T)
fn encode<T: EncoderValue>(&mut self, value: &T)
Encode the given
EncoderValue
into the buffersource§fn encode_with_len_prefix<Len: TryFrom<usize> + EncoderValue, T: EncoderValue>(
&mut self,
value: &T
)
fn encode_with_len_prefix<Len: TryFrom<usize> + EncoderValue, T: EncoderValue>( &mut self, value: &T )
Encode the given
EncoderValue
into the buffer with a prefix of Len
source§fn remaining_capacity(&self) -> usize
fn remaining_capacity(&self) -> usize
Returns the number of available bytes in the buffer
Auto Trait Implementations§
impl<'a> !Freeze for Buffer<'a>
impl<'a> RefUnwindSafe for Buffer<'a>
impl<'a> Send for Buffer<'a>
impl<'a> Sync for Buffer<'a>
impl<'a> Unpin for Buffer<'a>
impl<'a> !UnwindSafe for Buffer<'a>
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