pub enum Value {
}Expand description
A run-time value.
The data variants are data.md’s built-in types and types.md’s records,
enums, tuples and Unit. The last three are values a run holds but that
are not data: they have no equality, order, text or encoding, and every
operation that would need one refuses them with DataError::NotData.
An aggregate holding one is not data either, and the refusal is reached
when the operation reaches it.
Cloning is cheap: every aggregate shares its parts.
Variants§
Unit
(), the one value of Unit.
Bool(bool)
true or false.
Int(Int)
An integer.
Decimal(Decimal)
An exact decimal.
Text(Text)
A sequence of code points.
Bytes(Bytes)
A sequence of bytes.
List(List)
A list.
Dict(Dict)
A dictionary, sorted by key.
Set(Set)
A set, sorted.
Tuple(Tuple)
A tuple of at least two parts.
Record(Record)
A record value.
Variant(Variant)
An enum value: a constructor and its payload.
Duration(Duration)
A length of time.
Instant(Instant)
A point in time.
Native(Native)
A value the evaluator implements and this crate cannot see into: a function, a closure, a compiled pattern.
Task(TaskId)
A handle to a running task.
Host(HostToken)
A value of a host type: the token the host chose for it.
Implementations§
Source§impl Value
impl Value
Sourcepub fn list(items: impl IntoIterator<Item = Value>) -> Value
pub fn list(items: impl IntoIterator<Item = Value>) -> Value
Returns a list of items, in order.
Sourcepub fn tuple(parts: impl IntoIterator<Item = Value>) -> Value
pub fn tuple(parts: impl IntoIterator<Item = Value>) -> Value
Returns a tuple of parts, in order.
Source§impl Value
impl Value
Sourcepub fn depth_bound(&self) -> usize
pub fn depth_bound(&self) -> usize
How deeply the value nests as data: a scalar is 0 deep and an
aggregate one deeper than its deepest part, so [[1]] is 2 deep. A
task or a Native value is a handle, 0 deep whatever it holds, so
a function value adds no depth for what it captured.
It is exact for every value whose parts are data, and costs constant time: every aggregate records it when it is made, and a part cut from a list or a dictionary an entry was removed from measures what it holds.
Sourcepub fn may_hold_tasks(&self) -> bool
pub fn may_hold_tasks(&self) -> bool
Whether some part of the value is a task handle or a Native
value, which may itself hold one; false means no part is either.
It costs constant time, as Value::depth_bound does.
Sourcepub fn deeper_than(&self, bound: usize) -> bool
pub fn deeper_than(&self, bound: usize) -> bool
Whether the value nests more than bound levels deep, in constant
time.
Sourcepub fn identity(&self) -> Option<Identity>
pub fn identity(&self) -> Option<Identity>
Returns what tells this value apart from the values alive that were
made separately, or None for a value that history never points at.
It is Some for a Text, Bytes, a host token, a List, a Set, a
Dict, a tuple, a record and an enum value: the values history
writes once and points at afterwards (trace.md, Slots). It is
read from the shared parts the value is made of, in constant time,
so a clone answers as the original does. Two values that answer
alike are equal; two that answer differently may be equal too,
having been made separately, and two windows onto one list’s tree
are different lists and answer differently.
The answer means something only while the value, or a clone of it, is kept: once every clone is dropped, a value made later may reuse its memory and answer alike. A writer that remembers what it wrote by identity keeps a clone of each value it remembers.
Source§impl Value
impl Value
Sourcepub fn parts(&self) -> Parts<'_> ⓘ
pub fn parts(&self) -> Parts<'_> ⓘ
Returns the parts the value holds, in the order equality and order
read them: a list’s elements, a dictionary’s keys and values as key,
value, key, value in key order, a set’s members, a tuple’s, record’s
or enum value’s parts, and the values a Native value holds. A
scalar has none.
This is the one place that knows what an aggregate holds; every walk over a value’s parts reads it, so none recurses once per level.
Sourcepub fn part(&self, index: usize) -> Option<&Value>
pub fn part(&self, index: usize) -> Option<&Value>
Returns the part at index in Value::parts order, if there is
one: a dictionary’s entry i is its parts 2i, the key, and
2i + 1, the value.
Sourcepub fn walk(&self) -> Walk<'_> ⓘ
pub fn walk(&self) -> Walk<'_> ⓘ
Returns the value and every part inside it, each before its own
parts, keeping the parts still to visit on a stack on the heap, so a
value nested deeper than the native stack is walked like any other.
Walk::skip_current passes over the parts of the value last
returned.
Sourcepub fn same(&self, other: &Value) -> bool
pub fn same(&self, other: &Value) -> bool
Returns whether the two values are the same: equal as data, where
both are, and otherwise built alike, with the same host tokens, the
same task handles, and native values their carriers call the same
(Carry::same). A value shares its identity with itself and its
clones, which answers at once. Two values of different shapes are not
the same.
This is how a run’s history tells a value it recorded from one it meets again; it is an equivalence and orders nothing. The walk keeps its place on the heap.
Sourcepub fn first_difference<'a>(
&'a self,
other: &'a Value,
) -> Option<Difference<'a>>
pub fn first_difference<'a>( &'a self, other: &'a Value, ) -> Option<Difference<'a>>
Where self and other first differ by Value::same, in the order
their parts are compared: the path to the two parts that differ, and
those parts. None when they are the same.
Two aggregates of different lengths differ as wholes, at the path to them.