#[non_exhaustive]pub enum Format {
Packed,
Storage,
Wire,
Descriptive,
Json,
}api only.Expand description
The serialization format used for message bodies.
The format is negotiated per connection, see the [negotiation protocol] for the details of how. Message headers are never affected by this and always use a fixed envelope, which is what makes negotiation possible in the first place.
The variants are ordered from least to most capable. Each capability that is dropped makes the encoding more compact:
reorder | missing | unknown | self | |
|---|---|---|---|---|
Packed | ✗ | ✗ | ✗ | ✗ |
Storage | ✔ | ✔ | ✗ | ✗ |
Wire | ✔ | ✔ | ✔ | ✗ |
Descriptive | ✔ | ✔ | ✔ | ✔ |
Json | ✔ | ✔ | ✔ | ✔ |
reorderdetermines whether fields may be reordered in the model.missingdetermines whether decoding tolerates missing fields, which is what allows new optional fields to be added.unknowndetermines whether decoding can skip fields it does not know about. A format which can do this is fully upgrade safe, since an old peer can talk to a new one.selfdetermines whether the format is self-descriptive, so that the data can be decoded without the model.
§Examples
use musli_web::api::Format;
assert_eq!(Format::default(), Format::Wire);
assert!(Format::Wire.is_upgrade_safe());
assert!(!Format::Storage.is_upgrade_safe());
assert!(Format::Json.is_human_readable());Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Packed
The musli::packed format.
The most compact format, but it requires that both peers use exactly the same model. Suitable when client and server are deployed together.
Storage
The musli::storage format.
Tolerates missing fields, but cannot skip fields it does not know about.
Wire
The musli::wire format.
Fully upgrade safe, so peers built against different versions of the model can talk to each other. This is the default.
Descriptive
The musli::descriptive format.
Fully upgrade safe and self-descriptive, at the cost of a larger payload.
Json
The musli::json format.
Human readable, which is useful when the traffic has to be inspected by
hand. Encoded using the Text mode so that fields are keyed by name.
Implementations§
Source§impl Format
impl Format
Sourcepub const DEFAULT: Self = Self::Wire
pub const DEFAULT: Self = Self::Wire
The default format, which is Format::Wire.
This is used by a client which has not picked a format, and by a server for a connection which has not negotiated one.
§Examples
use musli_web::api::Format;
assert_eq!(Format::DEFAULT, Format::Wire);Sourcepub const ALL: &'static [Format]
pub const ALL: &'static [Format]
Every format in order of increasing capability.
Note that this includes formats which the crate might not have been
built with support for, see Format::is_supported.
§Examples
use musli_web::api::Format;
assert!(Format::ALL.contains(&Format::Json));Sourcepub const fn to_u8(self) -> u8
pub const fn to_u8(self) -> u8
Get the stable identifier used for this format on the wire.
Zero is never used, so it is available to indicate an absent format.
§Examples
use musli_web::api::Format;
assert_eq!(Format::Wire.to_u8(), 3);
assert_eq!(Format::from_u8(3), Some(Format::Wire));Sourcepub const fn from_u8(id: u8) -> Option<Self>
pub const fn from_u8(id: u8) -> Option<Self>
Construct a format from the stable identifier used on the wire.
Returns None if the identifier is not known, which is how a peer
built against an older version of this crate reports a format it has
never heard of.
§Examples
use musli_web::api::Format;
assert_eq!(Format::from_u8(1), Some(Format::Packed));
assert_eq!(Format::from_u8(0), None);
assert_eq!(Format::from_u8(200), None);Sourcepub const fn name(self) -> &'static str
pub const fn name(self) -> &'static str
The name of the format.
§Examples
use musli_web::api::Format;
assert_eq!(Format::Wire.name(), "wire");Sourcepub const fn is_upgrade_safe(self) -> bool
pub const fn is_upgrade_safe(self) -> bool
Test if the format can skip over unknown fields, making it fully upgrade safe.
§Examples
use musli_web::api::Format;
assert!(Format::Wire.is_upgrade_safe());
assert!(!Format::Packed.is_upgrade_safe());Sourcepub const fn is_self_descriptive(self) -> bool
pub const fn is_self_descriptive(self) -> bool
Test if the format is self-descriptive, so that data can be decoded without access to the model.
§Examples
use musli_web::api::Format;
assert!(Format::Descriptive.is_self_descriptive());
assert!(!Format::Wire.is_self_descriptive());Sourcepub const fn is_human_readable(self) -> bool
pub const fn is_human_readable(self) -> bool
Test if the format produces output which is meant to be read by humans.
§Examples
use musli_web::api::Format;
assert!(Format::Json.is_human_readable());
assert!(!Format::Wire.is_human_readable());Source§impl Format
impl Format
Sourcepub const fn is_supported(self) -> bool
pub const fn is_supported(self) -> bool
Test if this build of the crate has support for the format.
Formats are gated behind features, so a peer might genuinely be unable to speak a format which the other side asks for. This is what the negotiation protocol uses to decide whether a request can be honored.
§Examples
use musli_web::api::Format;
// The default format is always available.
assert!(Format::DEFAULT.is_supported());Trait Implementations§
impl Copy for Format
Source§impl Default for Format
impl Default for Format
Source§fn default() -> Self
fn default() -> Self
Construct the default format, which is Format::DEFAULT.
§Examples
use musli_web::api::Format;
assert_eq!(Format::default(), Format::Wire);impl Eq for Format
Source§impl Ord for Format
impl Ord for Format
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Format
impl PartialOrd for Format
impl StructuralPartialEq for Format
Auto Trait Implementations§
impl Freeze for Format
impl RefUnwindSafe for Format
impl Send for Format
impl Sync for Format
impl Unpin for Format
impl UnsafeUnpin for Format
impl UnwindSafe for Format
Blanket Implementations§
impl<Token, Builder, How> AllPropsFor<Builder, How> for Tokenwhere
Builder: Buildable<Token>,
<Builder as Buildable<Token>>::WrappedToken: HasAllProps<<Builder as Buildable<Token>>::Output, How>,
impl<Token, Builder, How> AllPropsFor<Builder, How> for Tokenwhere
Builder: Buildable<Token>,
<Builder as Buildable<Token>>::WrappedToken: HasAllProps<<Builder as Buildable<Token>>::Output, How>,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.impl<T> HasAllProps<(), T> for T
impl<T> HasAllProps<(), T> for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoPropValue<Option<T>> for T
impl<T> IntoPropValue<Option<T>> for T
Source§fn into_prop_value(self) -> Option<T>
fn into_prop_value(self) -> Option<T>
self to a value of a Properties struct.Source§impl<T> IntoPropValue<Option<T>> for T
impl<T> IntoPropValue<Option<T>> for T
Source§fn into_prop_value(self) -> Option<T>
fn into_prop_value(self) -> Option<T>
self to a value of a Properties struct.Source§impl<T> IntoPropValue<T> for T
impl<T> IntoPropValue<T> for T
Source§fn into_prop_value(self) -> T
fn into_prop_value(self) -> T
self to a value of a Properties struct.Source§impl<T> IntoPropValue<T> for T
impl<T> IntoPropValue<T> for T
Source§fn into_prop_value(self) -> T
fn into_prop_value(self) -> T
self to a value of a Properties struct.