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 inreservedis 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 invariantsnor inreserved. More dangerous thanon_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-bearingInlineType-shaped types — definitely notBrilligOpcode-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§
Trait Implementations§
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> 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
Mutably borrows from an owned value. Read more