Trait Decodable

Source
pub trait Decodable<Dec, Err>: Versioned<Err>
where Err: Error + From<Dec::Error>, Dec: Decoder, Self::Output: Decode<Dec>,
{ // Provided methods fn decode(decoder: &mut Dec) -> Result<Self::Output, Err> { ... } fn decode_with_version( decoder: &mut Dec, version: u32, ) -> Result<Self::Output, Err> { ... } unsafe fn decode_body(decoder: &mut Dec) -> Result<Self::Output, Err> { ... } }
Expand description

This trait is used to mark a versioned type as decodable. Usually this is provided by the versioned! macro.

Provided Methods§

Source

fn decode(decoder: &mut Dec) -> Result<Self::Output, Err>

Decodes versioned data and validates the version. Will consume the version from the reader.

§Errors
  • Returns an error if the version is invalid.
  • Returns an error if the data is invalid.
Source

fn decode_with_version( decoder: &mut Dec, version: u32, ) -> Result<Self::Output, Err>

Decodes the data with a provided version tag. Is helpful for use in combination with Upgrade.

§Errors
  • Returns an error if the version is invalid.
  • Returns an error if the data is invalid.
Source

unsafe fn decode_body(decoder: &mut Dec) -> Result<Self::Output, Err>

Decodes only the body, assuming the version has already been validated.

§Safety

This function is marked unsafe because it does not validate the version and when used without care might lead to data corruption or other issues.

§Errors
  • Returns an error if the data is invalid.

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.

Implementors§

Source§

impl<Latest, Prior, Dec, Err> Decodable<Dec, Err> for Upgrade<Latest, Prior, Err>
where Dec: Decoder, Prior: Versioned<Err> + Decodable<Dec, Err>, Prior::Output: Decode<Dec>, Latest: Versioned<Err> + Decodable<Dec, Err>, Latest::Output: TryFrom<Prior::Output> + Decode<Dec>, Err: Error + From<<Dec as Decoder>::Error> + From<<Latest::Output as TryFrom<Prior::Output>>::Error>,