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
Tuple(Vec<WireSchema>)
A fixed-arity heterogeneous sequence. Element order is significant.
Array
A fixed-length homogeneous sequence. Element order is significant.
Struct
A map of serialized field names, held in field-name order.
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.
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.
Implementations§
Source§impl WireSchema
impl WireSchema
Sourcepub fn option(inner: WireSchema) -> Self
pub fn option(inner: WireSchema) -> Self
An optional value.
Sourcepub fn seq(item: WireSchema) -> Self
pub fn seq(item: WireSchema) -> Self
A homogeneous sequence.
Sourcepub fn map(key: WireSchema, value: WireSchema) -> Self
pub fn map(key: WireSchema, value: WireSchema) -> Self
A map.
Sourcepub fn array(element: WireSchema, length: usize) -> Self
pub fn array(element: WireSchema, length: usize) -> Self
A fixed-length homogeneous sequence.
Sourcepub fn newtype(inner: WireSchema) -> Self
pub fn newtype(inner: WireSchema) -> Self
A newtype struct, which serde writes transparently.
Sourcepub fn structure(fields: impl IntoIterator<Item = WireField>) -> Self
pub fn structure(fields: impl IntoIterator<Item = WireField>) -> Self
A struct, normalized into field-name order.
Sourcepub fn enumeration(
representation: EnumRepresentation,
variants: impl IntoIterator<Item = WireVariant>,
) -> Self
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.
Sourcepub fn opaque(name: impl Into<String>, wire: WireSchema) -> Self
pub fn opaque(name: impl Into<String>, wire: WireSchema) -> Self
The declared wire form of a hand-written Serialize.
Sourcepub fn resolved(&self) -> &WireSchema
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.
Sourcepub fn canonical_json(&self) -> String
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
impl WireSchema
Sourcepub fn conforms(&self, value: &Value) -> Result<(), WireMismatch>
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
impl Clone for WireSchema
Source§fn clone(&self) -> WireSchema
fn clone(&self) -> WireSchema
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more