SizeHint

Trait SizeHint 

Source
pub trait SizeHint {
    // Required methods
    fn size_hint(data: &[u8], offset: usize) -> Result<usize, Error>;
    fn size_hint_(&self, data: &[u8], offset: usize) -> Result<usize, Error>;
}
Expand description

The SizeHint trait provides a mechanism to return the encoded bytes size of a decodable type.

It defines two methods for retrieving the size of an encoded message:

These methods are crucial in decoding scenarios where the full size of the message is not immediately available, helping to determine how many bytes need to be read.

Required Methods§

Source

fn size_hint(data: &[u8], offset: usize) -> Result<usize, Error>

size_hint is a static method that takes the raw data and an offset and returns the total size of the encoded message. This is particularly useful for types where the encoded size may vary based on the contents of the data, and we need to calculate how much space is required for decoding.

Source

fn size_hint_(&self, data: &[u8], offset: usize) -> Result<usize, Error>

size_hint_ is an instance method that performs the same function but allows the size to be be determined with respect to the current instance of the type.

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.

Implementations on Foreign Types§

Source§

impl SizeHint for Vec<FieldMarker>

Source§

fn size_hint(_data: &[u8], _offset: usize) -> Result<usize, Error>

Source§

fn size_hint_(&self, data: &[u8], offset: usize) -> Result<usize, Error>

Implementors§

Source§

impl SizeHint for FieldMarker

Source§

impl<T> SizeHint for T
where T: Fixed,