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§
Provided Methods§
Sourcefn absent() -> Option<Self>
fn absent() -> Option<Self>
The value of a field that isn’t there — None: the field is required.
Sourcefn encode(&self, w: &mut Writer)
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).
Sourcefn decode(d: &mut Decoder<'_>) -> Option<Self>
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).
Sourcefn pack(&self, p: &mut Packer)
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).
Sourcefn unpack(u: &mut Unpacker<'_>) -> Option<Self>
fn unpack(u: &mut Unpacker<'_>) -> Option<Self>
Reads itself out of a frame; None if the bytes aren’t what
Schema::pack writes.
Sourcefn pack_list(items: &[Self], p: &mut Packer)
fn pack_list(items: &[Self], p: &mut Packer)
A list of these packed: a count, then each one (floats raw).
Sourcefn unpack_list(u: &mut Unpacker<'_>) -> Option<Vec<Self>>
fn unpack_list(u: &mut Unpacker<'_>) -> Option<Vec<Self>>
A list of these out of a frame.
Sourcefn encode_list(items: &[Self], w: &mut Writer)
fn encode_list(items: &[Self], w: &mut Writer)
A list of these written straight (numbers pack theirs).
Sourcefn decode_list(d: &mut Decoder<'_>) -> Option<Vec<Self>>
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.
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§impl Schema for Arc<str>
A string shared without copying.
impl Schema for Arc<str>
A string shared without copying.
fn shape() -> Shape
fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<Arc<str>>
fn write(&self) -> Value
fn encode(&self, w: &mut Writer)
fn decode(d: &mut Decoder<'_>) -> Option<Arc<str>>
fn pack(&self, p: &mut Packer)
fn unpack(u: &mut Unpacker<'_>) -> Option<Arc<str>>
Source§impl Schema for Box<str>
impl Schema for Box<str>
fn shape() -> Shape
fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<Box<str>>
fn write(&self) -> Value
fn encode(&self, w: &mut Writer)
fn decode(d: &mut Decoder<'_>) -> Option<Box<str>>
fn pack(&self, p: &mut Packer)
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.
impl Schema for Cow<'static, str>
Text that may be a constant: borrowed where it’s written, owned once read.
fn shape() -> Shape
fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<Cow<'static, str>>
fn write(&self) -> Value
fn encode(&self, w: &mut Writer)
fn decode(d: &mut Decoder<'_>) -> Option<Cow<'static, str>>
fn pack(&self, p: &mut Packer)
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).
impl Schema for PathBuf
A file’s path, as text (a path that isn’t Unicode loses what isn’t).
fn shape() -> Shape
fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<PathBuf>
fn write(&self) -> Value
fn encode(&self, w: &mut Writer)
fn decode(d: &mut Decoder<'_>) -> Option<PathBuf>
fn pack(&self, p: &mut Packer)
fn unpack(u: &mut Unpacker<'_>) -> Option<PathBuf>
Source§impl Schema for String
impl Schema for String
fn shape() -> Shape
fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<String>
fn write(&self) -> Value
fn encode(&self, w: &mut Writer)
fn decode(d: &mut Decoder<'_>) -> Option<String>
fn pack(&self, p: &mut Packer)
fn unpack(u: &mut Unpacker<'_>) -> Option<String>
Source§impl Schema for bool
impl Schema for bool
fn shape() -> Shape
fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<bool>
fn write(&self) -> Value
fn encode(&self, w: &mut Writer)
fn decode(d: &mut Decoder<'_>) -> Option<bool>
fn pack(&self, p: &mut Packer)
fn unpack(u: &mut Unpacker<'_>) -> Option<bool>
Source§impl Schema for f32
impl Schema for f32
fn shape() -> Shape
fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<f32>
fn write(&self) -> Value
fn encode(&self, w: &mut Writer)
fn decode(d: &mut Decoder<'_>) -> Option<f32>
fn encode_list(items: &[f32], w: &mut Writer)
fn decode_list(d: &mut Decoder<'_>) -> Option<Vec<f32>>
fn pack(&self, p: &mut Packer)
fn unpack(u: &mut Unpacker<'_>) -> Option<f32>
fn pack_list(items: &[f32], p: &mut Packer)
fn unpack_list(u: &mut Unpacker<'_>) -> Option<Vec<f32>>
Source§impl Schema for f64
impl Schema for f64
fn shape() -> Shape
fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<f64>
fn write(&self) -> Value
fn encode(&self, w: &mut Writer)
fn decode(d: &mut Decoder<'_>) -> Option<f64>
fn encode_list(items: &[f64], w: &mut Writer)
fn decode_list(d: &mut Decoder<'_>) -> Option<Vec<f64>>
fn pack(&self, p: &mut Packer)
fn unpack(u: &mut Unpacker<'_>) -> Option<f64>
fn pack_list(items: &[f64], p: &mut Packer)
fn unpack_list(u: &mut Unpacker<'_>) -> Option<Vec<f64>>
Source§impl Schema for i8
impl Schema for i8
fn shape() -> Shape
fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<i8>
fn write(&self) -> Value
fn encode(&self, w: &mut Writer)
fn decode(d: &mut Decoder<'_>) -> Option<i8>
fn pack(&self, p: &mut Packer)
fn unpack(u: &mut Unpacker<'_>) -> Option<i8>
fn pack_list(items: &[i8], p: &mut Packer)
fn unpack_list(u: &mut Unpacker<'_>) -> Option<Vec<i8>>
fn encode_list(items: &[i8], w: &mut Writer)
fn decode_list(d: &mut Decoder<'_>) -> Option<Vec<i8>>
Source§impl Schema for i16
impl Schema for i16
fn shape() -> Shape
fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<i16>
fn write(&self) -> Value
fn encode(&self, w: &mut Writer)
fn decode(d: &mut Decoder<'_>) -> Option<i16>
fn pack(&self, p: &mut Packer)
fn unpack(u: &mut Unpacker<'_>) -> Option<i16>
fn pack_list(items: &[i16], p: &mut Packer)
fn unpack_list(u: &mut Unpacker<'_>) -> Option<Vec<i16>>
fn encode_list(items: &[i16], w: &mut Writer)
fn decode_list(d: &mut Decoder<'_>) -> Option<Vec<i16>>
Source§impl Schema for i32
impl Schema for i32
fn shape() -> Shape
fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<i32>
fn write(&self) -> Value
fn encode(&self, w: &mut Writer)
fn decode(d: &mut Decoder<'_>) -> Option<i32>
fn pack(&self, p: &mut Packer)
fn unpack(u: &mut Unpacker<'_>) -> Option<i32>
fn pack_list(items: &[i32], p: &mut Packer)
fn unpack_list(u: &mut Unpacker<'_>) -> Option<Vec<i32>>
fn encode_list(items: &[i32], w: &mut Writer)
fn decode_list(d: &mut Decoder<'_>) -> Option<Vec<i32>>
Source§impl Schema for i64
impl Schema for i64
fn shape() -> Shape
fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<i64>
fn write(&self) -> Value
fn encode(&self, w: &mut Writer)
fn decode(d: &mut Decoder<'_>) -> Option<i64>
fn pack(&self, p: &mut Packer)
fn unpack(u: &mut Unpacker<'_>) -> Option<i64>
fn pack_list(items: &[i64], p: &mut Packer)
fn unpack_list(u: &mut Unpacker<'_>) -> Option<Vec<i64>>
fn encode_list(items: &[i64], w: &mut Writer)
fn decode_list(d: &mut Decoder<'_>) -> Option<Vec<i64>>
Source§impl Schema for u8
impl Schema for u8
fn shape() -> Shape
fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<u8>
fn write(&self) -> Value
fn encode(&self, w: &mut Writer)
fn decode(d: &mut Decoder<'_>) -> Option<u8>
fn pack(&self, p: &mut Packer)
fn unpack(u: &mut Unpacker<'_>) -> Option<u8>
fn pack_list(items: &[u8], p: &mut Packer)
fn unpack_list(u: &mut Unpacker<'_>) -> Option<Vec<u8>>
fn encode_list(items: &[u8], w: &mut Writer)
fn decode_list(d: &mut Decoder<'_>) -> Option<Vec<u8>>
Source§impl Schema for u16
impl Schema for u16
fn shape() -> Shape
fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<u16>
fn write(&self) -> Value
fn encode(&self, w: &mut Writer)
fn decode(d: &mut Decoder<'_>) -> Option<u16>
fn pack(&self, p: &mut Packer)
fn unpack(u: &mut Unpacker<'_>) -> Option<u16>
fn pack_list(items: &[u16], p: &mut Packer)
fn unpack_list(u: &mut Unpacker<'_>) -> Option<Vec<u16>>
fn encode_list(items: &[u16], w: &mut Writer)
fn decode_list(d: &mut Decoder<'_>) -> Option<Vec<u16>>
Source§impl Schema for u32
impl Schema for u32
fn shape() -> Shape
fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<u32>
fn write(&self) -> Value
fn encode(&self, w: &mut Writer)
fn decode(d: &mut Decoder<'_>) -> Option<u32>
fn pack(&self, p: &mut Packer)
fn unpack(u: &mut Unpacker<'_>) -> Option<u32>
fn pack_list(items: &[u32], p: &mut Packer)
fn unpack_list(u: &mut Unpacker<'_>) -> Option<Vec<u32>>
fn encode_list(items: &[u32], w: &mut Writer)
fn decode_list(d: &mut Decoder<'_>) -> Option<Vec<u32>>
Source§impl Schema for u64
impl Schema for u64
fn shape() -> Shape
fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<u64>
fn write(&self) -> Value
fn encode(&self, w: &mut Writer)
fn decode(d: &mut Decoder<'_>) -> Option<u64>
fn pack(&self, p: &mut Packer)
fn unpack(u: &mut Unpacker<'_>) -> Option<u64>
fn pack_list(items: &[u64], p: &mut Packer)
fn unpack_list(u: &mut Unpacker<'_>) -> Option<Vec<u64>>
fn encode_list(items: &[u64], w: &mut Writer)
fn decode_list(d: &mut Decoder<'_>) -> Option<Vec<u64>>
Source§impl Schema for usize
impl Schema for usize
fn shape() -> Shape
fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<usize>
fn write(&self) -> Value
fn encode(&self, w: &mut Writer)
fn decode(d: &mut Decoder<'_>) -> Option<usize>
fn pack(&self, p: &mut Packer)
fn unpack(u: &mut Unpacker<'_>) -> Option<usize>
fn pack_list(items: &[usize], p: &mut Packer)
fn unpack_list(u: &mut Unpacker<'_>) -> Option<Vec<usize>>
fn encode_list(items: &[usize], w: &mut Writer)
fn decode_list(d: &mut Decoder<'_>) -> Option<Vec<usize>>
Source§impl<A, B, C, D> Schema for (A, B, C, D)
impl<A, B, C, D> Schema for (A, B, C, D)
Source§fn pack(&self, p: &mut Packer)
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.
fn shape() -> Shape
fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<(A, B, C, D)>
fn write(&self) -> Value
fn unpack(u: &mut Unpacker<'_>) -> Option<(A, B, C, D)>
Source§impl<A, B, C> Schema for (A, B, C)
impl<A, B, C> Schema for (A, B, C)
Source§fn pack(&self, p: &mut Packer)
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.
fn shape() -> Shape
fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<(A, B, C)>
fn write(&self) -> Value
fn unpack(u: &mut Unpacker<'_>) -> Option<(A, B, C)>
Source§impl<A, B> Schema for (A, B)
impl<A, B> Schema for (A, B)
Source§fn pack(&self, p: &mut Packer)
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.
fn shape() -> Shape
fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<(A, B)>
fn write(&self) -> Value
fn unpack(u: &mut Unpacker<'_>) -> Option<(A, B)>
Source§impl<T, const N: usize> Schema for [T; N]where
T: Schema,
impl<T, const N: usize> Schema for [T; N]where
T: Schema,
fn shape() -> Shape
fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<[T; N]>
fn write(&self) -> Value
fn encode(&self, w: &mut Writer)
fn decode(d: &mut Decoder<'_>) -> Option<[T; N]>
fn pack(&self, p: &mut Packer)
fn unpack(u: &mut Unpacker<'_>) -> Option<[T; N]>
Source§impl<T> Schema for BTreeSet<T>
A set: a list, in order, each once.
impl<T> Schema for BTreeSet<T>
A set: a list, in order, each once.
Source§impl<T> Schema for Box<T>where
T: Schema,
impl<T> Schema for Box<T>where
T: Schema,
fn shape() -> Shape
fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<Box<T>>
fn write(&self) -> Value
fn encode(&self, w: &mut Writer)
fn decode(d: &mut Decoder<'_>) -> Option<Box<T>>
fn pack(&self, p: &mut Packer)
fn unpack(u: &mut Unpacker<'_>) -> Option<Box<T>>
fn absent() -> Option<Box<T>>
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.
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.
fn shape() -> Shape
fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<Box<[T]>>
fn write(&self) -> Value
fn encode(&self, w: &mut Writer)
fn decode(d: &mut Decoder<'_>) -> Option<Box<[T]>>
fn pack(&self, p: &mut Packer)
fn unpack(u: &mut Unpacker<'_>) -> Option<Box<[T]>>
Source§impl<T> Schema for Option<T>where
T: Schema,
impl<T> Schema for Option<T>where
T: Schema,
fn shape() -> Shape
fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<Option<T>>
fn write(&self) -> Value
fn encode(&self, w: &mut Writer)
fn decode(d: &mut Decoder<'_>) -> Option<Option<T>>
fn pack(&self, p: &mut Packer)
fn unpack(u: &mut Unpacker<'_>) -> Option<Option<T>>
fn absent() -> Option<Option<T>>
fn skip(&self) -> bool
Source§impl<T> Schema for Vec<T>where
T: Schema,
impl<T> Schema for Vec<T>where
T: Schema,
fn shape() -> Shape
fn read(v: &ValueRef<'_>, cx: &mut Reader<'_>) -> Option<Vec<T>>
fn write(&self) -> Value
fn encode(&self, w: &mut Writer)
fn decode(d: &mut Decoder<'_>) -> Option<Vec<T>>
fn pack(&self, p: &mut Packer)
fn unpack(u: &mut Unpacker<'_>) -> Option<Vec<T>>
Implementors§
impl Schema for AnyRefOrTag
impl Schema for Atom
Text everywhere but in a frame, which carries its number.
impl Schema for Code
Written as its code; packed in a frame as an Atom (its number).
impl Schema for Color
impl Schema for DefinitionDoc
impl Schema for Diagnostic
impl Schema for Dictionary
impl Schema for FieldDoc
impl Schema for Image
impl Schema for KindName
A kind’s name as text: checked when it’s read.
impl Schema for Path
A path as its steps.
impl Schema for Ref
A reference of any kind: in a frame, its kind and its id, as text.
impl Schema for Res
impl Schema for Seg
impl Schema for Severity
impl Schema for ShapeDoc
impl Schema for ShapeNode
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.
impl Schema for Uid
impl Schema for Value
impl Schema for VariantDoc
impl<K: Kind<Id = String>> Schema for OneOrTag<K>
impl<K: Kind> Schema for TagId<K>
impl<K> Schema for Id<K>where
K: Kind,
In a frame, only its id (the kind is the field’s).