pub trait ChunkMutExt: ChunkMut {
// Provided methods
fn put_varint<V>(
&mut self,
value: &V,
) -> Result<NonZeroUsize, EncodeVarintError>
where V: Varint { ... }
fn put_varint_at<V>(
&mut self,
value: &V,
offset: usize,
) -> Result<NonZeroUsize, EncodeVarintAtError>
where V: Varint { ... }
fn write_varint<V>(
&mut self,
value: &V,
) -> Result<NonZeroUsize, EncodeVarintError>
where V: Varint { ... }
}Expand description
A trait that extends ChunkMut with additional methods.
Provided Methods§
Sourcefn put_varint<V>(
&mut self,
value: &V,
) -> Result<NonZeroUsize, EncodeVarintError>where
V: Varint,
Available on crate feature varint only.
fn put_varint<V>(
&mut self,
value: &V,
) -> Result<NonZeroUsize, EncodeVarintError>where
V: Varint,
varint only.Puts type in LEB128 format to the buffer without advancing the internal cursor.
Uses the LEB128 encoding format. The number of bytes written depends on the value being encoded.
Returns Ok(bytes_written) on success, or Err(EncodeVarintError) if there’s
insufficient space or an encoding error occurs.
§Examples
use bufkit::{ChunkMut, ChunkMutExt};
let mut buf = [0u8; 24];
let mut slice = &mut buf[..];
let written = slice.put_varint(&42u32).unwrap();
// written will be 1 for small values like 42Sourcefn put_varint_at<V>(
&mut self,
value: &V,
offset: usize,
) -> Result<NonZeroUsize, EncodeVarintAtError>where
V: Varint,
Available on crate feature varint only.
fn put_varint_at<V>(
&mut self,
value: &V,
offset: usize,
) -> Result<NonZeroUsize, EncodeVarintAtError>where
V: Varint,
varint only.Puts type in LEB128 format to the buffer at the specified offset without advancing the internal cursor.
Uses the LEB128 encoding format. The number of bytes written depends on the value being encoded.
Returns Ok(bytes_written) on success, or Err(EncodeVarintAtError) if the offset
is out of bounds, there’s insufficient space, or an encoding error occurs.
§Examples
use bufkit::{ChunkMut, ChunkMutExt};
let mut buf = [0u8; 24];
let mut slice = &mut buf[..];
let written = slice.put_varint_at(&42u32, 3).unwrap();
// The varint is written starting at offset 3
// If the offset is out of bounds or there's insufficient space,
// it will return an error.
let err = slice.put_varint_at(&42u32, 30).unwrap_err();
let err = slice.put_varint_at(&8442u32, 23).unwrap_err();Sourcefn write_varint<V>(
&mut self,
value: &V,
) -> Result<NonZeroUsize, EncodeVarintError>where
V: Varint,
Available on crate feature varint only.
fn write_varint<V>(
&mut self,
value: &V,
) -> Result<NonZeroUsize, EncodeVarintError>where
V: Varint,
varint only.Writes type in LEB128 format to the buffer without advancing the internal cursor.
Uses the LEB128 encoding format. The number of bytes written depends on the value being encoded.
Returns Ok(bytes_written) on success, or Err(EncodeVarintError) if there’s
insufficient space or an encoding error occurs.
§Examples
use bufkit::{ChunkMut, ChunkMutExt};
let mut buf = [0u8; 24];
let mut slice = &mut buf[..];
let written = slice.write_varint(&42u32).unwrap();
// written will be 1 for small values like 42
assert_eq!(slice.remaining_mut(), 24 - written.get());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.