Skip to main content

Datum

Enum Datum 

Source
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.

Fields

§tag: Symbol

Node tag symbol.

§fields: Vec<(Symbol, Datum)>

Named field bindings in declaration order.

Implementations§

Source§

impl Datum

Source

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).

Source

pub fn content_id(&self) -> Result<ContentId>

Returns the content id of this datum under the kernel datum algorithm.

Trait Implementations§

Source§

impl Clone for Datum

Source§

fn clone(&self) -> Datum

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Datum

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Datum

Source§

impl From<Datum> for Expr

Source§

fn from(datum: Datum) -> Self

Converts to this type from the input type.
Source§

impl Hash for Datum

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Datum

Source§

fn eq(&self, other: &Datum) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Datum

Source§

impl TryFrom<Expr> for Datum

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(expr: Expr) -> Result<Self>

Performs the conversion.

Auto Trait Implementations§

§

impl Freeze for Datum

§

impl RefUnwindSafe for Datum

§

impl Send for Datum

§

impl Sync for Datum

§

impl Unpin for Datum

§

impl UnsafeUnpin for Datum

§

impl UnwindSafe for Datum

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.