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
impl DecodeFormat
Sourcepub const fn media_type(self) -> &'static str
pub const fn media_type(self) -> &'static str
The format’s canonical media type.
Sourcepub fn from_content_type(content_type: &str) -> Option<Self>
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.
Sourcepub fn decode_slice<T: DeserializeOwned>(
self,
body: &[u8],
) -> Result<T, FormatError>
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).
Sourcepub fn decode_reader<T, R>(self, reader: R) -> Result<T, FormatError>where
T: DeserializeOwned,
R: Read,
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
impl Clone for DecodeFormat
Source§fn clone(&self) -> DecodeFormat
fn clone(&self) -> DecodeFormat
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more