pub enum Datum {
Nil,
Bool(bool),
Number(NumberLiteral),
Symbol(Symbol),
String(String),
Bytes(Vec<u8>),
List(Vec<Datum>),
Vector(Vec<Datum>),
Map(Vec<(Datum, Datum)>),
Set(Vec<Datum>),
Node {
tag: Symbol,
fields: Vec<(Symbol, Datum)>,
},
}Expand description
Content-addressable data form of the substrate.
A Datum is the canonical, hashable projection of an Expr: the same
value always hashes to the same ContentId, independent of how it was
written. The kernel fixes the datum shape and its content-hash algorithm;
libraries supply the DatumStores that
intern and resolve data.
§Examples
let datum = Datum::String("hello".to_owned());
let id = datum.content_id().unwrap();
// The same datum always hashes to the same content id.
assert_eq!(id, Datum::String("hello".to_owned()).content_id().unwrap());Variants§
Nil
The nil datum.
Bool(bool)
A boolean datum.
Number(NumberLiteral)
A number literal in some domain.
Symbol(Symbol)
A symbol datum.
String(String)
A UTF-8 string datum.
Bytes(Vec<u8>)
A byte-string datum.
List(Vec<Datum>)
An ordered list datum.
Vector(Vec<Datum>)
An ordered vector datum.
Map(Vec<(Datum, Datum)>)
A map datum as ordered key/value pairs; duplicate keys are rejected when hashing.
Set(Vec<Datum>)
A set datum; duplicate entries are rejected when hashing.
Node
A tagged node datum with named fields, the datum form of an
Expr::Extension.
Implementations§
Source§impl Datum
impl Datum
Sourcepub fn canonical_bytes(&self) -> Result<Vec<u8>>
pub fn canonical_bytes(&self) -> Result<Vec<u8>>
Returns the canonical byte encoding used to compute the content id.
The encoding is deterministic: equal data produces equal bytes, with map and set entries ordered by their hashes so member order does not affect the result. Returns an error when the datum cannot be canonicalized (for example, a map with duplicate keys).
Sourcepub fn content_id(&self) -> Result<ContentId>
pub fn content_id(&self) -> Result<ContentId>
Returns the content id of this datum under the kernel datum algorithm.