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§
Sourcefn size_hint(data: &[u8], offset: usize) -> Result<usize, Error>
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.
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.