#[non_exhaustive]pub enum DynamicSchema {
Null,
Bool,
U64,
I64,
F64,
String,
Bytes,
Seq(Box<DynamicSchema>),
Map(Vec<(String, DynamicSchema)>),
Enum(Vec<EnumVariantSchema>),
}Expand description
Describes the byte-stream shape of a postcard-encoded payload at one version. See module docs for the variant ↔ wire-format mapping.
DynamicSchema is 'static-friendly: literal schemas can live in
const-fn-adjacent contexts (e.g. a LazyLock registry) without
borrowing.
Boxing the inner schema in Seq keeps the enum’s size_of
reasonable (the alternative — Vec<DynamicSchema> of length 1 —
is overkill for the single-element case and reads worse).
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Null
Unit / zero-byte field. Postcard emits no bytes for ().
Bool
Boolean — single byte 0 / 1.
U64
Unsigned 64-bit integer (varint).
I64
Signed 64-bit integer (zigzag varint).
F64
64-bit IEEE-754 float (8 LE bytes).
String
UTF-8 string (varint length + bytes).
Bytes
Raw byte sequence (varint length + bytes).
Seq(Box<DynamicSchema>)
Variable-length sequence of elem-shaped values.
Map(Vec<(String, DynamicSchema)>)
Postcard-encoded struct described as an ordered list of
(field_name, field_schema) pairs. Order MUST match the
Rust declaration order of the struct that wrote the bytes —
postcard reads fields positionally, so a transposed schema
will mis-decode the payload as silently as any out-of-order
tuple destructure.
Enum(Vec<EnumVariantSchema>)
Postcard-encoded enum: a varint u32 discriminant followed by
the matched variant’s payload bytes. variants MUST be sorted
strictly ascending by EnumVariantSchema::discriminant; the
walker binary-searches the list and a missing discriminant
surfaces as Error::SchemaTypeMismatch.
Unit variants set payload = DynamicSchema::Null. Newtype
variants set payload to the inner type’s schema. Tuple and
struct variants set payload = DynamicSchema::Map(...) with
the variant’s fields in declaration order; for tuple variants
the field names are the synthetic strings "0", "1", …
(postcard writes tuple variants positionally — the same wire
shape as a Rust struct’s bytes).
Implementations§
Source§impl DynamicSchema
impl DynamicSchema
Sourcepub fn seq(elem: DynamicSchema) -> Self
pub fn seq(elem: DynamicSchema) -> Self
Convenience constructor for a Seq schema with elem as
the element shape.
Sourcepub fn map<I, S>(fields: I) -> Self
pub fn map<I, S>(fields: I) -> Self
Convenience constructor for a Map schema. fields is the
(name, schema) list in declaration order.
Sourcepub fn enumeration<I>(variants: I) -> Selfwhere
I: IntoIterator<Item = EnumVariantSchema>,
pub fn enumeration<I>(variants: I) -> Selfwhere
I: IntoIterator<Item = EnumVariantSchema>,
Convenience constructor for an Enum schema. variants is
the list of variants; the caller is responsible for keeping
them sorted ascending by discriminant — the walker
debug-asserts the invariant on the first decode of each
schema. Use EnumVariantSchema::new for each entry.
Trait Implementations§
Source§impl Clone for DynamicSchema
impl Clone for DynamicSchema
Source§fn clone(&self) -> DynamicSchema
fn clone(&self) -> DynamicSchema
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DynamicSchema
impl Debug for DynamicSchema
Source§impl PartialEq for DynamicSchema
impl PartialEq for DynamicSchema
Source§fn eq(&self, other: &DynamicSchema) -> bool
fn eq(&self, other: &DynamicSchema) -> bool
self and other values to be equal, and is used by ==.