pub enum EncodeFormat {
Json,
Yaml,
MessagePack,
Postcard,
}Expand description
A Serde wire format this crate can encode as a bounded stream.
Variants§
Json
application/json.
Yaml
application/yaml (RFC 9512).
MessagePack
application/vnd.msgpack, encoded with named fields so the
output stays self-describing.
Postcard
application/x-postcard.
Implementations§
Source§impl EncodeFormat
impl EncodeFormat
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 media-type value to an encodable format.
Parameters are ignored; matching is case-insensitive; documented
pre-registration aliases are accepted for YAML and MessagePack.
Sourcepub fn encode_vec<T: Serialize>(self, value: &T) -> Result<Vec<u8>, FormatError>
pub fn encode_vec<T: Serialize>(self, value: &T) -> Result<Vec<u8>, FormatError>
Encode a bounded value into one in-memory buffer.
For payloads that must exist before headers are sent (an error
envelope, a small control document). Ordinary payloads stream
through EncodeFormat::encode_stream.
§Errors
FormatError::Encoding when the value cannot be encoded in
this format.
Sourcepub fn encode_stream<T>(self, value: T) -> EncodedStream
pub fn encode_stream<T>(self, value: T) -> EncodedStream
Encode an owned value as an asynchronous, bounded chunk stream.
The serializer runs on a blocking worker and hands chunks of at
most 64 KiB through a bounded channel, so memory stays
O(channel × chunk) regardless of the encoded size and a slow
consumer backpressures the serializer instead of buffering. An
encoding failure surfaces as a trailing Err item — the stream
is never silently truncated.
Must be called from within a Tokio runtime.
Trait Implementations§
Source§impl Clone for EncodeFormat
impl Clone for EncodeFormat
Source§fn clone(&self) -> EncodeFormat
fn clone(&self) -> EncodeFormat
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more