Skip to main content

DynamicSchema

Enum DynamicSchema 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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

Source

pub fn seq(elem: DynamicSchema) -> DynamicSchema

Convenience constructor for a Seq schema with elem as the element shape.

Source

pub fn map<I, S>(fields: I) -> DynamicSchema
where I: IntoIterator<Item = (S, DynamicSchema)>, S: Into<String>,

Convenience constructor for a Map schema. fields is the (name, schema) list in declaration order.

Source

pub fn enumeration<I>(variants: I) -> DynamicSchema

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

Source§

fn clone(&self) -> DynamicSchema

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for DynamicSchema

Source§

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

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

impl PartialEq for DynamicSchema

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 Eq for DynamicSchema

Source§

impl StructuralPartialEq for DynamicSchema

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more