pub trait Encoder: Sized {
const SPECIALIZES_BYTES: bool = false;
// Required methods
fn write_sized<F: FnOnce(&mut [u8])>(&mut self, len: usize, write: F);
fn write_slice(&mut self, slice: &[u8]);
fn write_zerocopy<T: IntoBytes + FromBytes + Unaligned, F: FnOnce(&mut T)>(
&mut self,
write: F,
);
fn write_repeated(&mut self, count: usize, value: u8);
fn capacity(&self) -> usize;
fn len(&self) -> usize;
// Provided methods
fn encode<T: EncoderValue>(&mut self, value: &T) { ... }
fn encode_with_len_prefix<Len: TryFrom<usize> + EncoderValue, T: EncoderValue>(
&mut self,
value: &T,
)
where Len::Error: Debug { ... }
fn write_bytes(&mut self, bytes: Bytes) { ... }
fn is_empty(&self) -> bool { ... }
fn remaining_capacity(&self) -> usize { ... }
}
Provided Associated Constants§
Sourceconst SPECIALIZES_BYTES: bool = false
const SPECIALIZES_BYTES: bool = false
Set to true
if the particular encoder specializes on the bytes implementation
Required Methods§
Sourcefn 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 position
Sourcefn write_slice(&mut self, slice: &[u8])
fn write_slice(&mut self, slice: &[u8])
Copies the slice into the buffer
Sourcefn write_zerocopy<T: IntoBytes + FromBytes + Unaligned, F: FnOnce(&mut T)>(
&mut self,
write: F,
)
fn write_zerocopy<T: IntoBytes + FromBytes + Unaligned, F: FnOnce(&mut T)>( &mut self, write: F, )
Writes a zerocopy value to the buffer
Sourcefn write_repeated(&mut self, count: usize, value: u8)
fn write_repeated(&mut self, count: usize, value: u8)
Repeatedly write a byte value
for a given count
let mut buffer = vec![255; 1024];
let mut encoder = EncoderBuffer::new(&mut buffer);
encoder.encode(&1u8);
encoder.write_repeated(4, 0);
assert_eq!(&buffer[0..6], &[1, 0, 0, 0, 0, 255]);
Provided Methods§
Sourcefn encode<T: EncoderValue>(&mut self, value: &T)
fn encode<T: EncoderValue>(&mut self, value: &T)
Encode the given EncoderValue
into the buffer
Sourcefn 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
fn write_bytes(&mut self, bytes: Bytes)
Sourcefn remaining_capacity(&self) -> usize
fn remaining_capacity(&self) -> usize
Returns the number of available bytes in the buffer
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.