Trait postcard::de_flavors::Flavor
source · pub trait Flavor<'de>: 'de {
type Remainder: 'de;
type Source: 'de;
// Required methods
fn pop(&mut self) -> Result<u8>;
fn try_take_n(&mut self, ct: usize) -> Result<&'de [u8]>;
fn finalize(self) -> Result<Self::Remainder>;
// Provided method
fn size_hint(&self) -> Option<usize> { ... }
}
Expand description
The deserialization Flavor trait
This is used as the primary way to decode serialized data from some kind of buffer, or modify that data in a middleware style pattern.
See the module level docs for an example of how flavors are used.
Required Associated Types§
sourcetype Remainder: 'de
type Remainder: 'de
The remaining data of this flavor after deserializing has completed.
Typically, this includes the remaining buffer that was not used for deserialization, and in cases of more complex flavors, any additional information that was decoded or otherwise calculated during the deserialization process.
Required Methods§
sourcefn try_take_n(&mut self, ct: usize) -> Result<&'de [u8]>
fn try_take_n(&mut self, ct: usize) -> Result<&'de [u8]>
Attempt to take the next ct
bytes from the serialized message
Provided Methods§
sourcefn size_hint(&self) -> Option<usize>
fn size_hint(&self) -> Option<usize>
Returns the number of bytes remaining in the message, if known.
§Implementation notes
It is not enforced that this number is exactly correct. A flavor may yield less or more bytes than the what is hinted at by this function.
size_hint()
is primarily intended to be used for optimizations such as
reserving space for deserialized items, but must not be trusted to
e.g., omit bounds checks in unsafe code. An incorrect implementation of
size_hint()
should not lead to memory safety violations.
That said, the implementation should provide a correct estimation, because otherwise it would be a violation of the trait’s protocol.
The default implementation returns None
which is correct for any flavor.