Skip to main content

DecodeFormat

Enum DecodeFormat 

Source
pub enum DecodeFormat {
    Json,
    MessagePack,
    Postcard,
}
Expand description

A Serde wire format this crate can decode incrementally from a reader, without ever owning the complete input.

Whole-document formats (YAML, TOML) are deliberately absent: their available decoders require the full input in memory, which defeats the bounded-memory contract. Reject them upstream with a typed unsupported-media-type failure instead.

Variants§

§

Json

application/json.

§

MessagePack

application/vnd.msgpack, self-describing (named fields).

§

Postcard

application/x-postcard — not self-describing; callers must know the schema out of band.

Implementations§

Source§

impl DecodeFormat

Source

pub const fn media_type(self) -> &'static str

The format’s canonical media type.

Source

pub const fn name(self) -> &'static str

The format’s display name for error detail.

Source

pub fn from_content_type(content_type: &str) -> Option<Self>

Resolve a Content-Type value to a decodable format.

Parameters (; charset=…) are ignored; matching is case-insensitive. Documented pre-registration aliases are accepted for MessagePack. None means the media type is not an incrementally decodable format.

Source

pub fn decode_slice<T: DeserializeOwned>( self, body: &[u8], ) -> Result<T, FormatError>

Decode a complete in-memory document.

For inputs that are already bounded (a small control message, a test fixture). Streaming inputs go through DecodeFormat::decode_reader.

§Errors

FormatError::MalformedDocument with decoder position detail (where the decoder provides it).

Source

pub fn decode_reader<T, R>(self, reader: R) -> Result<T, FormatError>
where T: DeserializeOwned, R: Read,

Decode a document incrementally from reader.

The decoder pulls from the reader as it parses, so the caller never owns the complete input. Run it on a blocking-capable thread when the reader bridges an asynchronous source.

A reader that enforces a size limit should surface the limit hit as io::Error::other(crate::PayloadLimitExceeded); it is reported as FormatError::PayloadTooLarge.

§Errors

FormatError::Read / FormatError::PayloadTooLarge when the reader fails, FormatError::MalformedDocument when the input is not a valid document in this format.

Trait Implementations§

Source§

impl Clone for DecodeFormat

Source§

fn clone(&self) -> DecodeFormat

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for DecodeFormat

Source§

impl Debug for DecodeFormat

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for DecodeFormat

Source§

impl PartialEq for DecodeFormat

Source§

fn eq(&self, other: &DecodeFormat) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for DecodeFormat

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.