Struct Sum

Source
pub struct Sum {
    pub variants: &'static [Variant],
    pub reserved: &'static [Tag],
    pub on_reserved_tag: Option<Tag>,
    pub on_unknown_tag: Option<Tag>,
}
Expand description

A sum type — a discriminated union of Variants.

reserved lists retired variant tags. Like Product::reserved, this is always a compile-time tag-reuse guard; whether the runtime decoder routes such tags to a fallback variant is controlled by on_reserved_tag.

on_reserved_tag and on_unknown_tag opt into runtime-lenient decode of variant tags. Unlike products’ allow_unknown_tags (which just skips an entry), sums can’t skip a discriminator — the value is the discriminator — so the tolerance is expressed as “route to a designated fallback variant, discarding the payload”:

  • on_reserved_tag — when set, the wire tag of the unit variant that acts as the backward-compat fallback. The macro fills it in iff a variant in the source carries #[tagged(on_reserved)]. On decode, any wire tag in reserved is routed here (payload discarded).
  • on_unknown_tag — same shape, but for forward-compat: a variant marked #[tagged(on_unknown)] catches any wire tag that’s neither in variants nor in reserved. More dangerous than on_reserved: silently swallows real corruption alongside future-version tags, so opt in only when the fallback variant is a safe semantic substitute for “anything I don’t recognize” (e.g. metadata-bearing InlineType-shaped types — definitely not BrilligOpcode-shaped ones, where an unknown discriminator means we can’t execute the program).

A single variant may carry both #[tagged(on_reserved)] and #[tagged(on_unknown)] when the user wants the unified-catch-all behavior; in that case both fields point at the same tag.

Fields§

§variants: &'static [Variant]§reserved: &'static [Tag]§on_reserved_tag: Option<Tag>§on_unknown_tag: Option<Tag>

Implementations§

Source§

impl Sum

Source

pub fn variant_for(self, variant_name: &str) -> Option<Variant>

Look up a variant’s metadata by its serde name.

Source

pub fn is_reserved(self, tag: Tag) -> bool

Whether tag is in the sum’s reserved list (a retired variant tag).

Trait Implementations§

Source§

impl Clone for Sum

Source§

fn clone(&self) -> Sum

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 Sum

Source§

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

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

impl Copy for Sum

Auto Trait Implementations§

§

impl Freeze for Sum

§

impl RefUnwindSafe for Sum

§

impl Send for Sum

§

impl Sync for Sum

§

impl Unpin for Sum

§

impl UnwindSafe for Sum

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.