pub struct Desc { /* private fields */ }Expand description
A canonical description, built by writing and read as bytes.
The bytes are the whole point: they are what gets stored, what gets hashed
into the Tag, and what a binding in another language has to produce
exactly. Nothing here depends on Rust.
Implementations§
Source§impl Desc
impl Desc
Sourcepub fn from_bytes(bytes: impl Into<Vec<u8>>) -> Desc
pub fn from_bytes(bytes: impl Into<Vec<u8>>) -> Desc
A description someone else produced, from the catalogue or the wire.
Sourcepub fn as_text(&self) -> String
pub fn as_text(&self) -> String
The description as text, for a message or a log line. It is all ASCII apart from names, which are UTF-8, so this never fails in practice.
Sourcepub fn map(&mut self, key: fn(&mut Desc), value: fn(&mut Desc))
pub fn map(&mut self, key: fn(&mut Desc), value: fn(&mut Desc))
A mapping, key type then value type.
Sourcepub fn vector(&mut self, dim: u32, metric: Metric)
pub fn vector(&mut self, dim: u32, metric: Metric)
A vector of dim dimensions compared with metric.
Sourcepub fn reference(&mut self, name: &str)
pub fn reference(&mut self, name: &str)
A named reference, which is what a recursive type writes on the way
down. Written for you by Desc::strukt; call it directly only when
building a description by hand.
Sourcepub fn strukt(&mut self, name: &str, fields: &[(&str, fn(&mut Desc))])
pub fn strukt(&mut self, name: &str, fields: &[(&str, fn(&mut Desc))])
A struct, with its fields in declaration order.
Order is layout, so it is part of the shape and reordering fields is a
breaking change (15 section 5). That is why this takes a slice rather
than a map.
If name is already being written further up, this writes a reference
instead and does not descend, which is what makes a linked list or a
tree describable at all.
Sourcepub fn enumeration(&mut self, name: &str, variants: &[&str])
pub fn enumeration(&mut self, name: &str, variants: &[&str])
An enumeration, with its variants in declaration order.
Variants carry no payload here. A variant that carries data is a struct in a field of its own, which is how it has to be written until the grammar grows a form for it.