Enum EncodingStrategy

Source
pub enum EncodingStrategy {
    Tagged,
    Array,
}
Expand description

On-wire shape for product types (structs, tuple structs, enum-variant payloads). Picked per-type on the Serializer (see Serializer::new / Serializer::with_strategy). Enum variants are always int-keyed under MsgpackTagged regardless of strategy — the strategy only affects struct shape.

  • EncodingStrategy::Tagged (default) — int-keyed fixmap {0: a, 1: b, …}. Schema-evolution friendly: identification is by tag, so fields can be added, removed (via #[tagged(reserved(...))]), or reordered freely. Costs one byte per field for the tag.
  • EncodingStrategy::Array — positional fixarray [a, b, …], fields emitted in tag-ascending order. Minimum overhead. Identification is by position, so evolvability is limited to trailing changes:
    • Adding a trailing field is backward-compat when the field is marked #[serde(default)] — V1 wire (shorter) decodes into V2 type, the default fills the new position.
    • Removing a trailing field is forward-compat when the type opts into #[tagged(allow_unknown_tags)] — V2 wire (longer) decodes into V1 type, the extra trailing position is ignored.
    • Anything else (middle insert/remove, reorder, type change) is wire-breaking. Pick this strategy for small leaf types where size wins over flexibility and the type is unlikely to need middle-of-shape edits.

Auto-downgrade to Tagged. If a type has #[tagged(reserved(N))] where N falls between (or before) the active tags, requesting Array for it would corrupt round-trips: V2’s positional wire only carries active values, but the decoder walks a merged-sorted layout of (active + reserved) tags and would drain a wire byte at the reserved slot intended for a later active field. The encoder detects this and silently switches to Tagged for that product only — other types in the same serializer keep their configured strategy. Strictly-trailing reserved tags (every reserved tag greater than every active tag) keep Array: the decoder hits wire_remaining == 0 before reaching the trailing reserved slot, so positional alignment holds. The migration guide in the crate README walks through both cases with examples.

The decoder probes the wire shape (fixmap vs. fixarray) per struct at decode time, so a single buffer can mix both strategies across nested types freely.

Variants§

§

Tagged

Int-keyed map. Default — most backward/forward compatible.

§

Array

Positional array. Smaller; not schema-evolvable.

Trait Implementations§

Source§

impl Clone for EncodingStrategy

Source§

fn clone(&self) -> EncodingStrategy

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for EncodingStrategy

Source§

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

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

impl Default for EncodingStrategy

Source§

fn default() -> EncodingStrategy

Returns the “default value” for a type. Read more
Source§

impl PartialEq for EncodingStrategy

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for EncodingStrategy

Source§

impl Eq for EncodingStrategy

Source§

impl StructuralPartialEq for EncodingStrategy

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<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<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> 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 = Infallible

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.