Skip to main content

WireSchema

Enum WireSchema 

Source
pub enum WireSchema {
Show 24 variants Bool, U8, U16, U32, U64, I8, I16, I32, I64, F32, F64, String, Bytes, Unit, Freeform, Option(Box<WireSchema>), Seq(Box<WireSchema>), Map { key: Box<WireSchema>, value: Box<WireSchema>, }, Tuple(Vec<WireSchema>), Array { element: Box<WireSchema>, length: usize, }, Struct { fields: Vec<WireField>, }, Newtype(Box<WireSchema>), Enum { representation: EnumRepresentation, variants: Vec<WireVariant>, }, Opaque { name: String, wire: Box<WireSchema>, },
}
Expand description

One serialized wire shape.

The variants are exactly the serde data-model shapes this workspace’s process contracts reach for. A shape serde can express but Phoxal never writes is deliberately absent: an author who needs one adds it here on purpose rather than getting an approximation.

Variants§

§

Bool

§

U8

§

U16

§

U32

§

U64

§

I8

§

I16

§

I32

§

I64

§

F32

§

F64

§

String

§

Bytes

A byte string written through serialize_bytes, which every Phoxal codec keeps distinct from a sequence of integers.

§

Unit

The unit value: null in JSON, nil in MessagePack.

§

Freeform

A schema-carrying document whose interior is genuinely open, such as an embedded JSON Schema. Nothing below this point is a compatibility axis.

§

Option(Box<WireSchema>)

§

Seq(Box<WireSchema>)

§

Map

Fields

§

Tuple(Vec<WireSchema>)

A fixed-arity heterogeneous sequence. Element order is significant.

§

Array

A fixed-length homogeneous sequence. Element order is significant.

Fields

§element: Box<WireSchema>
§length: usize
§

Struct

A map of serialized field names, held in field-name order.

Fields

§fields: Vec<WireField>
§

Newtype(Box<WireSchema>)

A newtype struct, which serde writes as its inner value with no wrapping at all.

§

Enum

A sum type. A tagged one holds its variants in variant-name order; an untagged one holds them in declaration order, because that order is what decides which variant an ambiguous value resolves to.

Fields

§representation: EnumRepresentation
§variants: Vec<WireVariant>
§

Opaque

A type whose Serialize is hand-written, together with the wire form that implementation declares.

The name says which implementation owns the form, so a checker can point at the hand-maintained boundary rather than at an anonymous string somewhere inside a document.

Fields

§name: String

Implementations§

Source§

impl WireSchema

Source

pub fn option(inner: WireSchema) -> Self

An optional value.

Source

pub fn seq(item: WireSchema) -> Self

A homogeneous sequence.

Source

pub fn map(key: WireSchema, value: WireSchema) -> Self

A map.

Source

pub fn array(element: WireSchema, length: usize) -> Self

A fixed-length homogeneous sequence.

Source

pub fn newtype(inner: WireSchema) -> Self

A newtype struct, which serde writes transparently.

Source

pub fn structure(fields: impl IntoIterator<Item = WireField>) -> Self

A struct, normalized into field-name order.

Source

pub fn enumeration( representation: EnumRepresentation, variants: impl IntoIterator<Item = WireVariant>, ) -> Self

A sum type, normalized into variant-name order wherever that order is not itself a wire fact.

A tagged enum is resolved by looking its tag up, so reordering its variants changes nothing and the canonical form sorts them. An untagged enum is resolved by trying its variants in declaration order and keeping the first that decodes, so for that one representation the order is part of the contract and is preserved exactly.

Source

pub fn opaque(name: impl Into<String>, wire: WireSchema) -> Self

The declared wire form of a hand-written Serialize.

Source

pub fn resolved(&self) -> &WireSchema

The shape with every transparent wrapper removed.

Opaque names an implementation and Newtype is written with no wrapping at all, so neither changes what a decoder sees. Structural questions - “is this a map?” - are asked of this.

Source

pub fn canonical_json(&self) -> String

The canonical rendering: sorted keys, no whitespace, one shape per declaration.

Byte equality of two renderings is exactly structural equality of the two schemas, which is what makes a stored baseline comparable with a plain string compare.

Source§

impl WireSchema

Source

pub fn conforms(&self, value: &Value) -> Result<(), WireMismatch>

Check one serialized value against this shape.

This is what makes a hand-written DescribeWire trustworthy: a test serializes a real value and asserts the declared schema names the shape that actually came out, so a declaration cannot quietly drift from the serializer beside it.

The value is inspected as serde_json::Value, which collapses two distinctions the serde data model keeps. Integer width is checked by range rather than by type, and a byte string arrives as an array of byte-valued numbers (what serde_json writes for serialize_bytes) or as a string, so both are accepted for WireSchema::Bytes.

Trait Implementations§

Source§

impl Clone for WireSchema

Source§

fn clone(&self) -> WireSchema

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 WireSchema

Source§

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

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

impl Eq for WireSchema

Source§

impl PartialEq for WireSchema

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for WireSchema

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.