pub trait BufMutExt: BufMut {
// Provided methods
fn put_varint<V>(&mut self, value: &V) -> Result<usize, WriteVarintError>
where V: Varint { ... }
fn put_varint_at<V>(
&mut self,
value: &V,
offset: usize,
) -> Result<usize, WriteVarintAtError>
where V: Varint { ... }
}Expand description
A trait that extends BufMut with additional methods.
Provided Methods§
Sourcefn put_varint<V>(&mut self, value: &V) -> Result<usize, WriteVarintError>where
V: Varint,
Available on crate feature varing only.
fn put_varint<V>(&mut self, value: &V) -> Result<usize, WriteVarintError>where
V: Varint,
varing only.Writes a type in LEB128 format to the buffer.
Uses the LEB128 encoding format. The number of bytes written depends on the value being encoded.
Returns Ok(bytes_written) on success, or Err(WriteVarintError) if there’s
insufficient space or an encoding error occurs.
§Examples
use bufkit::{BufMut, BufMutExt};
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<usize, WriteVarintAtError>where
V: Varint,
Available on crate feature varing only.
fn put_varint_at<V>(
&mut self,
value: &V,
offset: usize,
) -> Result<usize, WriteVarintAtError>where
V: Varint,
varing only.Writes a type in LEB128 format to the buffer at the specified offset.
Uses the LEB128 encoding format. The number of bytes written depends on the value being encoded.
Returns Ok(bytes_written) on success, or Err(WriteVarintAtError) if the offset
is out of bounds, there’s insufficient space, or an encoding error occurs.
§Examples
use bufkit::{BufMut, BufMutExt};
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();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.