pub unsafe trait FromBinary<'a>: Sized {
const POD: bool = false;
// Required method
fn decode_binary(decoder: &mut Decoder<'a>) -> Self;
}Expand description
A trait for parsing a value from a compact binary representation.
§Safety
This trait is safe to implement if you only override decode_binary and leave
other methods as default. However, setting POD = true requires additional
safety considerations.
§Usage
Given a decoder, decode_binary will attempt to decode Self from the prefix
of the decoder. This method always returns a value, even in case of an error.
When an error occurs, a default value is returned. This approach is primarily
an optimization but can also be used to extract partial values when parsing
as a whole has failed.
§Error Handling
Errors are stored in the decoder rather than being returned directly by
decode_binary.
§Plain Old Data (POD)
Setting POD = true indicates that this type can be directly memory-copied
from the input and maintains the same representation as if it was encoded
field-by-field in the binary decoder.
§Requirements for POD = true:
- Every bit must be valid for the type and layout.
- There must be no padding between fields.
- Fields must be laid out in the same order as they are encoded and decoded
by
decode_binary.
Provided Associated Constants§
Required Methods§
Sourcefn decode_binary(decoder: &mut Decoder<'a>) -> Self
fn decode_binary(decoder: &mut Decoder<'a>) -> Self
Decodes Self from the given decoder.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".