Skip to main content

Schema

Trait Schema 

Source
pub trait Schema: Sized {
Show 13 methods // Required methods fn shape() -> Shape; fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<Self>; fn write(&self) -> Value; // Provided methods fn absent() -> Option<Self> { ... } fn skip(&self) -> bool { ... } fn encode(&self, w: &mut Writer) { ... } fn decode(d: &mut Decoder<'_>) -> Option<Self> { ... } fn pack(&self, p: &mut Packer) { ... } fn unpack(u: &mut Unpacker<'_>) -> Option<Self> { ... } fn pack_list(items: &[Self], p: &mut Packer) { ... } fn unpack_list(u: &mut Unpacker<'_>) -> Option<Vec<Self>> { ... } fn encode_list(items: &[Self], w: &mut Writer) { ... } fn decode_list(d: &mut Decoder<'_>) -> Option<Vec<Self>> { ... }
}
Expand description

A format: a type that reads, writes, encodes, packs and describes itself.

Required Methods§

Source

fn shape() -> Shape

What the format looks like.

Source

fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<Self>

Reads v. Problems go to cx at its current path; None when the value couldn’t be read (the problem is in cx).

Source

fn write(&self) -> Value

The value, as the format writes it.

Provided Methods§

Source

fn absent() -> Option<Self>

The value of a field that isn’t there — None: the field is required.

Source

fn skip(&self) -> bool

Whether a struct leaves this field out when writing it.

Source

fn encode(&self, w: &mut Writer)

Writes itself in the binary form, straight — Schema::write’s value encoded, unless the type knows better (derived ones do).

Source

fn decode(d: &mut Decoder<'_>) -> Option<Self>

Reads itself from the binary form, straight; None when it isn’t what Schema::encode writes — then read_bytes reads the slow way, which says what’s wrong. Through a value unless the type knows better (derived ones do).

Source

fn pack(&self, p: &mut Packer)

Packs itself into a frame (crate::frame): its binary form as bytes, unless the type packs itself (derived ones and plain types do).

Source

fn unpack(u: &mut Unpacker<'_>) -> Option<Self>

Reads itself out of a frame; None if the bytes aren’t what Schema::pack writes.

Source

fn pack_list(items: &[Self], p: &mut Packer)

A list of these packed: a count, then each one (floats raw).

Source

fn unpack_list(u: &mut Unpacker<'_>) -> Option<Vec<Self>>

A list of these out of a frame.

Source

fn encode_list(items: &[Self], w: &mut Writer)

A list of these written straight (numbers pack theirs).

Source

fn decode_list(d: &mut Decoder<'_>) -> Option<Vec<Self>>

A list of these read straight.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Schema for ()

A number as carried (an i64) back to T: out of T’s range, none. Nothing: what a call answers when it only says it’s done.

Source§

fn shape() -> Shape

Source§

fn read(_v: &ValueRef<'_>, _cx: &mut Reader<'_>) -> Option<()>

Source§

fn write(&self) -> Value

Source§

impl Schema for Arc<str>

A string shared without copying.

Source§

fn shape() -> Shape

Source§

fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<Arc<str>>

Source§

fn write(&self) -> Value

Source§

fn encode(&self, w: &mut Writer)

Source§

fn decode(d: &mut Decoder<'_>) -> Option<Arc<str>>

Source§

fn pack(&self, p: &mut Packer)

Source§

fn unpack(u: &mut Unpacker<'_>) -> Option<Arc<str>>

Source§

impl Schema for Box<str>

Source§

fn shape() -> Shape

Source§

fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<Box<str>>

Source§

fn write(&self) -> Value

Source§

fn encode(&self, w: &mut Writer)

Source§

fn decode(d: &mut Decoder<'_>) -> Option<Box<str>>

Source§

fn pack(&self, p: &mut Packer)

Source§

fn unpack(u: &mut Unpacker<'_>) -> Option<Box<str>>

Source§

impl Schema for Cow<'static, str>

Text that may be a constant: borrowed where it’s written, owned once read.

Source§

fn shape() -> Shape

Source§

fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<Cow<'static, str>>

Source§

fn write(&self) -> Value

Source§

fn encode(&self, w: &mut Writer)

Source§

fn decode(d: &mut Decoder<'_>) -> Option<Cow<'static, str>>

Source§

fn pack(&self, p: &mut Packer)

Source§

fn unpack(u: &mut Unpacker<'_>) -> Option<Cow<'static, str>>

Source§

impl Schema for PathBuf

A file’s path, as text (a path that isn’t Unicode loses what isn’t).

Source§

fn shape() -> Shape

Source§

fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<PathBuf>

Source§

fn write(&self) -> Value

Source§

fn encode(&self, w: &mut Writer)

Source§

fn decode(d: &mut Decoder<'_>) -> Option<PathBuf>

Source§

fn pack(&self, p: &mut Packer)

Source§

fn unpack(u: &mut Unpacker<'_>) -> Option<PathBuf>

Source§

impl Schema for String

Source§

fn shape() -> Shape

Source§

fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<String>

Source§

fn write(&self) -> Value

Source§

fn encode(&self, w: &mut Writer)

Source§

fn decode(d: &mut Decoder<'_>) -> Option<String>

Source§

fn pack(&self, p: &mut Packer)

Source§

fn unpack(u: &mut Unpacker<'_>) -> Option<String>

Source§

impl Schema for bool

Source§

fn shape() -> Shape

Source§

fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<bool>

Source§

fn write(&self) -> Value

Source§

fn encode(&self, w: &mut Writer)

Source§

fn decode(d: &mut Decoder<'_>) -> Option<bool>

Source§

fn pack(&self, p: &mut Packer)

Source§

fn unpack(u: &mut Unpacker<'_>) -> Option<bool>

Source§

impl Schema for f32

Source§

fn shape() -> Shape

Source§

fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<f32>

Source§

fn write(&self) -> Value

Source§

fn encode(&self, w: &mut Writer)

Source§

fn decode(d: &mut Decoder<'_>) -> Option<f32>

Source§

fn encode_list(items: &[f32], w: &mut Writer)

Source§

fn decode_list(d: &mut Decoder<'_>) -> Option<Vec<f32>>

Source§

fn pack(&self, p: &mut Packer)

Source§

fn unpack(u: &mut Unpacker<'_>) -> Option<f32>

Source§

fn pack_list(items: &[f32], p: &mut Packer)

Source§

fn unpack_list(u: &mut Unpacker<'_>) -> Option<Vec<f32>>

Source§

impl Schema for f64

Source§

fn shape() -> Shape

Source§

fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<f64>

Source§

fn write(&self) -> Value

Source§

fn encode(&self, w: &mut Writer)

Source§

fn decode(d: &mut Decoder<'_>) -> Option<f64>

Source§

fn encode_list(items: &[f64], w: &mut Writer)

Source§

fn decode_list(d: &mut Decoder<'_>) -> Option<Vec<f64>>

Source§

fn pack(&self, p: &mut Packer)

Source§

fn unpack(u: &mut Unpacker<'_>) -> Option<f64>

Source§

fn pack_list(items: &[f64], p: &mut Packer)

Source§

fn unpack_list(u: &mut Unpacker<'_>) -> Option<Vec<f64>>

Source§

impl Schema for i8

Source§

fn shape() -> Shape

Source§

fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<i8>

Source§

fn write(&self) -> Value

Source§

fn encode(&self, w: &mut Writer)

Source§

fn decode(d: &mut Decoder<'_>) -> Option<i8>

Source§

fn pack(&self, p: &mut Packer)

Source§

fn unpack(u: &mut Unpacker<'_>) -> Option<i8>

Source§

fn pack_list(items: &[i8], p: &mut Packer)

Source§

fn unpack_list(u: &mut Unpacker<'_>) -> Option<Vec<i8>>

Source§

fn encode_list(items: &[i8], w: &mut Writer)

Source§

fn decode_list(d: &mut Decoder<'_>) -> Option<Vec<i8>>

Source§

impl Schema for i16

Source§

fn shape() -> Shape

Source§

fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<i16>

Source§

fn write(&self) -> Value

Source§

fn encode(&self, w: &mut Writer)

Source§

fn decode(d: &mut Decoder<'_>) -> Option<i16>

Source§

fn pack(&self, p: &mut Packer)

Source§

fn unpack(u: &mut Unpacker<'_>) -> Option<i16>

Source§

fn pack_list(items: &[i16], p: &mut Packer)

Source§

fn unpack_list(u: &mut Unpacker<'_>) -> Option<Vec<i16>>

Source§

fn encode_list(items: &[i16], w: &mut Writer)

Source§

fn decode_list(d: &mut Decoder<'_>) -> Option<Vec<i16>>

Source§

impl Schema for i32

Source§

fn shape() -> Shape

Source§

fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<i32>

Source§

fn write(&self) -> Value

Source§

fn encode(&self, w: &mut Writer)

Source§

fn decode(d: &mut Decoder<'_>) -> Option<i32>

Source§

fn pack(&self, p: &mut Packer)

Source§

fn unpack(u: &mut Unpacker<'_>) -> Option<i32>

Source§

fn pack_list(items: &[i32], p: &mut Packer)

Source§

fn unpack_list(u: &mut Unpacker<'_>) -> Option<Vec<i32>>

Source§

fn encode_list(items: &[i32], w: &mut Writer)

Source§

fn decode_list(d: &mut Decoder<'_>) -> Option<Vec<i32>>

Source§

impl Schema for i64

Source§

fn shape() -> Shape

Source§

fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<i64>

Source§

fn write(&self) -> Value

Source§

fn encode(&self, w: &mut Writer)

Source§

fn decode(d: &mut Decoder<'_>) -> Option<i64>

Source§

fn pack(&self, p: &mut Packer)

Source§

fn unpack(u: &mut Unpacker<'_>) -> Option<i64>

Source§

fn pack_list(items: &[i64], p: &mut Packer)

Source§

fn unpack_list(u: &mut Unpacker<'_>) -> Option<Vec<i64>>

Source§

fn encode_list(items: &[i64], w: &mut Writer)

Source§

fn decode_list(d: &mut Decoder<'_>) -> Option<Vec<i64>>

Source§

impl Schema for u8

Source§

fn shape() -> Shape

Source§

fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<u8>

Source§

fn write(&self) -> Value

Source§

fn encode(&self, w: &mut Writer)

Source§

fn decode(d: &mut Decoder<'_>) -> Option<u8>

Source§

fn pack(&self, p: &mut Packer)

Source§

fn unpack(u: &mut Unpacker<'_>) -> Option<u8>

Source§

fn pack_list(items: &[u8], p: &mut Packer)

Source§

fn unpack_list(u: &mut Unpacker<'_>) -> Option<Vec<u8>>

Source§

fn encode_list(items: &[u8], w: &mut Writer)

Source§

fn decode_list(d: &mut Decoder<'_>) -> Option<Vec<u8>>

Source§

impl Schema for u16

Source§

fn shape() -> Shape

Source§

fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<u16>

Source§

fn write(&self) -> Value

Source§

fn encode(&self, w: &mut Writer)

Source§

fn decode(d: &mut Decoder<'_>) -> Option<u16>

Source§

fn pack(&self, p: &mut Packer)

Source§

fn unpack(u: &mut Unpacker<'_>) -> Option<u16>

Source§

fn pack_list(items: &[u16], p: &mut Packer)

Source§

fn unpack_list(u: &mut Unpacker<'_>) -> Option<Vec<u16>>

Source§

fn encode_list(items: &[u16], w: &mut Writer)

Source§

fn decode_list(d: &mut Decoder<'_>) -> Option<Vec<u16>>

Source§

impl Schema for u32

Source§

fn shape() -> Shape

Source§

fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<u32>

Source§

fn write(&self) -> Value

Source§

fn encode(&self, w: &mut Writer)

Source§

fn decode(d: &mut Decoder<'_>) -> Option<u32>

Source§

fn pack(&self, p: &mut Packer)

Source§

fn unpack(u: &mut Unpacker<'_>) -> Option<u32>

Source§

fn pack_list(items: &[u32], p: &mut Packer)

Source§

fn unpack_list(u: &mut Unpacker<'_>) -> Option<Vec<u32>>

Source§

fn encode_list(items: &[u32], w: &mut Writer)

Source§

fn decode_list(d: &mut Decoder<'_>) -> Option<Vec<u32>>

Source§

impl Schema for u64

Source§

fn shape() -> Shape

Source§

fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<u64>

Source§

fn write(&self) -> Value

Source§

fn encode(&self, w: &mut Writer)

Source§

fn decode(d: &mut Decoder<'_>) -> Option<u64>

Source§

fn pack(&self, p: &mut Packer)

Source§

fn unpack(u: &mut Unpacker<'_>) -> Option<u64>

Source§

fn pack_list(items: &[u64], p: &mut Packer)

Source§

fn unpack_list(u: &mut Unpacker<'_>) -> Option<Vec<u64>>

Source§

fn encode_list(items: &[u64], w: &mut Writer)

Source§

fn decode_list(d: &mut Decoder<'_>) -> Option<Vec<u64>>

Source§

impl Schema for usize

Source§

fn shape() -> Shape

Source§

fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<usize>

Source§

fn write(&self) -> Value

Source§

fn encode(&self, w: &mut Writer)

Source§

fn decode(d: &mut Decoder<'_>) -> Option<usize>

Source§

fn pack(&self, p: &mut Packer)

Source§

fn unpack(u: &mut Unpacker<'_>) -> Option<usize>

Source§

fn pack_list(items: &[usize], p: &mut Packer)

Source§

fn unpack_list(u: &mut Unpacker<'_>) -> Option<Vec<usize>>

Source§

fn encode_list(items: &[usize], w: &mut Writer)

Source§

fn decode_list(d: &mut Decoder<'_>) -> Option<Vec<usize>>

Source§

impl<A, B, C, D> Schema for (A, B, C, D)
where A: Schema, B: Schema, C: Schema, D: Schema,

Source§

fn pack(&self, p: &mut Packer)

In a frame it’s a list of any values, as its shape says: each item in its binary form.

Source§

fn shape() -> Shape

Source§

fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<(A, B, C, D)>

Source§

fn write(&self) -> Value

Source§

fn unpack(u: &mut Unpacker<'_>) -> Option<(A, B, C, D)>

Source§

impl<A, B, C> Schema for (A, B, C)
where A: Schema, B: Schema, C: Schema,

Source§

fn pack(&self, p: &mut Packer)

In a frame it’s a list of any values, as its shape says: each item in its binary form.

Source§

fn shape() -> Shape

Source§

fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<(A, B, C)>

Source§

fn write(&self) -> Value

Source§

fn unpack(u: &mut Unpacker<'_>) -> Option<(A, B, C)>

Source§

impl<A, B> Schema for (A, B)
where A: Schema, B: Schema,

Source§

fn pack(&self, p: &mut Packer)

In a frame it’s a list of any values, as its shape says: each item in its binary form.

Source§

fn shape() -> Shape

Source§

fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<(A, B)>

Source§

fn write(&self) -> Value

Source§

fn unpack(u: &mut Unpacker<'_>) -> Option<(A, B)>

Source§

impl<T, E> Schema for Result<T, E>
where T: Schema, E: Schema,

What may fail: { "ok": T } or { "err": E }.

Source§

fn shape() -> Shape

Source§

fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<Result<T, E>>

Source§

fn write(&self) -> Value

Source§

impl<T, S> Schema for HashMap<String, T, S>
where T: Schema, S: BuildHasher + Default,

Source§

fn shape() -> Shape

Source§

fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<HashMap<String, T, S>>

Source§

fn write(&self) -> Value

Source§

impl<T, const N: usize> Schema for [T; N]
where T: Schema,

Source§

fn shape() -> Shape

Source§

fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<[T; N]>

Source§

fn write(&self) -> Value

Source§

fn encode(&self, w: &mut Writer)

Source§

fn decode(d: &mut Decoder<'_>) -> Option<[T; N]>

Source§

fn pack(&self, p: &mut Packer)

Source§

fn unpack(u: &mut Unpacker<'_>) -> Option<[T; N]>

Source§

impl<T> Schema for BTreeMap<String, T>
where T: Schema,

Source§

fn shape() -> Shape

Source§

fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<BTreeMap<String, T>>

Source§

fn write(&self) -> Value

Source§

impl<T> Schema for BTreeSet<T>
where T: Schema + Ord + Clone,

A set: a list, in order, each once.

Source§

fn pack(&self, p: &mut Packer)

In a frame it’s a list, as its shape says.

Source§

fn shape() -> Shape

Source§

fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<BTreeSet<T>>

Source§

fn write(&self) -> Value

Source§

fn encode(&self, w: &mut Writer)

Source§

fn decode(d: &mut Decoder<'_>) -> Option<BTreeSet<T>>

Source§

fn unpack(u: &mut Unpacker<'_>) -> Option<BTreeSet<T>>

Source§

impl<T> Schema for Box<T>
where T: Schema,

Source§

fn shape() -> Shape

Source§

fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<Box<T>>

Source§

fn write(&self) -> Value

Source§

fn encode(&self, w: &mut Writer)

Source§

fn decode(d: &mut Decoder<'_>) -> Option<Box<T>>

Source§

fn pack(&self, p: &mut Packer)

Source§

fn unpack(u: &mut Unpacker<'_>) -> Option<Box<T>>

Source§

fn absent() -> Option<Box<T>>

Source§

fn skip(&self) -> bool

Source§

impl<T> Schema for Box<[T]>
where T: Schema,

A string that won’t change: a pointer and a length, no spare capacity (String’s third word) — what big tables of names keep. A list that won’t change: no spare capacity.

Source§

fn shape() -> Shape

Source§

fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<Box<[T]>>

Source§

fn write(&self) -> Value

Source§

fn encode(&self, w: &mut Writer)

Source§

fn decode(d: &mut Decoder<'_>) -> Option<Box<[T]>>

Source§

fn pack(&self, p: &mut Packer)

Source§

fn unpack(u: &mut Unpacker<'_>) -> Option<Box<[T]>>

Source§

impl<T> Schema for Option<T>
where T: Schema,

Source§

fn shape() -> Shape

Source§

fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<Option<T>>

Source§

fn write(&self) -> Value

Source§

fn encode(&self, w: &mut Writer)

Source§

fn decode(d: &mut Decoder<'_>) -> Option<Option<T>>

Source§

fn pack(&self, p: &mut Packer)

Source§

fn unpack(u: &mut Unpacker<'_>) -> Option<Option<T>>

Source§

fn absent() -> Option<Option<T>>

Source§

fn skip(&self) -> bool

Source§

impl<T> Schema for Vec<T>
where T: Schema,

Source§

fn shape() -> Shape

Source§

fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<Vec<T>>

Source§

fn write(&self) -> Value

Source§

fn encode(&self, w: &mut Writer)

Source§

fn decode(d: &mut Decoder<'_>) -> Option<Vec<T>>

Source§

fn pack(&self, p: &mut Packer)

Source§

fn unpack(u: &mut Unpacker<'_>) -> Option<Vec<T>>

Implementors§

Source§

impl Schema for AnyRefOrTag

Source§

impl Schema for Atom

Text everywhere but in a frame, which carries its number.

Source§

impl Schema for Code

Written as its code; packed in a frame as an Atom (its number).

Source§

impl Schema for Color

Source§

impl Schema for DefinitionDoc

Source§

impl Schema for Diagnostic

Source§

impl Schema for Dictionary

Source§

impl Schema for FieldDoc

Source§

impl Schema for Image

Source§

impl Schema for KindName

A kind’s name as text: checked when it’s read.

Source§

impl Schema for Path

A path as its steps.

Source§

impl Schema for Ref

A reference of any kind: in a frame, its kind and its id, as text.

Source§

impl Schema for Res

Source§

impl Schema for Seg

Source§

impl Schema for Severity

Source§

impl Schema for ShapeDoc

Source§

impl Schema for ShapeNode

Source§

impl Schema for Text

Read as its reference when it’s one, so a tool sees every reference a text makes; every other form is its stored form’s.

Source§

impl Schema for Uid

Source§

impl Schema for Value

Source§

impl Schema for VariantDoc

Source§

impl<K: Kind<Id = String>> Schema for OneOrTag<K>

Source§

impl<K: Kind> Schema for TagId<K>

Source§

impl<K> Schema for Id<K>
where K: Kind,

In a frame, only its id (the kind is the field’s).

Source§

impl<T> Schema for OneOrList<T>
where T: Schema,

Source§

impl<T> Schema for Ordered<T>
where T: Schema,

Source§

impl<T> Schema for Stream<T>
where T: Schema,