Skip to main content

Value

Enum Value 

Source
pub enum Value {
Show 17 variants Unit, Bool(bool), Int(Int), Decimal(Decimal), Text(Text), Bytes(Bytes), List(List), Dict(Dict), Set(Set), Tuple(Tuple), Record(Record), Variant(Variant), Duration(Duration), Instant(Instant), Native(Native), Task(TaskId), Host(HostToken),
}
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

Source

pub fn text(text: &str) -> Value

Returns the value text holds.

Source

pub fn int(value: i64) -> Value

Returns the integer value.

Source

pub fn list(items: impl IntoIterator<Item = Value>) -> Value

Returns a list of items, in order.

Source

pub fn tuple(parts: impl IntoIterator<Item = Value>) -> Value

Returns a tuple of parts, in order.

Source

pub fn as_list(&self) -> Option<&List>

The list this is, if it is one.

Source§

impl Value

Source

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.

Source

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.

Source

pub fn deeper_than(&self, bound: usize) -> bool

Whether the value nests more than bound levels deep, in constant time.

Source

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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

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 Value

Source§

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

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

impl Element for Value

Auto Trait Implementations§

§

impl !RefUnwindSafe for Value

§

impl !UnwindSafe for Value

§

impl Forget for Value

§

impl Freeze for Value
where *const u8 is !null: Freeze, PhantomData<u64>: Freeze, *const ArcInner<Inner<Run>> is !null: Freeze, PhantomData<ArcInner<Inner<Run>>>: Freeze, *const ArcInner<OnceLock<Arc<str>>> is !null: Freeze, PhantomData<ArcInner<OnceLock<Arc<str>>>>: Freeze, *const ArcInner<[u8]> is !null: Freeze, PhantomData<ArcInner<[u8]>>: Freeze, *const ArcInner<Vec<Value>> is !null: Freeze, PhantomData<ArcInner<Vec<Value>>>: Freeze, *const ArcInner<Inner<Value>> is !null: Freeze, PhantomData<ArcInner<Inner<Value>>>: Freeze, *const ArcInner<Inner<(Value, Value)>> is !null: Freeze, PhantomData<ArcInner<Inner<(Value, Value)>>>: Freeze, *const ArcInner<Inner<Member>> is !null: Freeze, PhantomData<ArcInner<Inner<Member>>>: Freeze, *const ArcInner<[Value]> is !null: Freeze, PhantomData<ArcInner<[Value]>>: Freeze, *const ArcInner<RecordShape> is !null: Freeze, PhantomData<ArcInner<RecordShape>>: Freeze, *const ArcInner<EnumShape> is !null: Freeze, PhantomData<ArcInner<EnumShape>>: Freeze, *const ArcInner<dyn Carry> is !null: Freeze, PhantomData<ArcInner<dyn Carry>>: Freeze, *const ArcInner<str> is !null: Freeze, PhantomData<ArcInner<str>>: Freeze,

§

impl Move for Value

§

impl Send for Value
where RawVecInner: Send, Arc<Inner<Run>>: Send, Arc<OnceLock<Arc<str>>>: Send, Arc<[u8]>: Send, Arc<Vec<Value>>: Send, Arc<Inner<Value>>: Send, Arc<Inner<(Value, Value)>>: Send, Arc<Inner<Member>>: Send, Arc<[Value]>: Send, Arc<RecordShape>: Send, Arc<EnumShape>: Send, Arc<dyn Carry>: Send, Arc<str>: Send,

§

impl Sync for Value
where RawVecInner: Sync, Arc<Inner<Run>>: Sync, Arc<OnceLock<Arc<str>>>: Sync, Arc<[u8]>: Sync, Arc<Vec<Value>>: Sync, Arc<Inner<Value>>: Sync, Arc<Inner<(Value, Value)>>: Sync, Arc<Inner<Member>>: Sync, Arc<[Value]>: Sync, Arc<RecordShape>: Sync, Arc<EnumShape>: Sync, Arc<dyn Carry>: Sync, Arc<str>: Sync,

§

impl Unpin for Value
where *const u8 is !null: Unpin, Arc<Inner<Run>>: Unpin, Arc<OnceLock<Arc<str>>>: Unpin, Arc<[u8]>: Unpin, Arc<Vec<Value>>: Unpin, Arc<Inner<Value>>: Unpin, Arc<Inner<(Value, Value)>>: Unpin, Arc<Inner<Member>>: Unpin, Arc<[Value]>: Unpin, Arc<RecordShape>: Unpin, Arc<EnumShape>: Unpin, Arc<dyn Carry>: Unpin, Arc<str>: Unpin,

§

impl UnsafeUnpin for Value
where *const u8 is !null: UnsafeUnpin, PhantomData<u64>: UnsafeUnpin, *const ArcInner<Inner<Run>> is !null: UnsafeUnpin, PhantomData<ArcInner<Inner<Run>>>: UnsafeUnpin, *const ArcInner<OnceLock<Arc<str>>> is !null: UnsafeUnpin, PhantomData<ArcInner<OnceLock<Arc<str>>>>: UnsafeUnpin, *const ArcInner<[u8]> is !null: UnsafeUnpin, PhantomData<ArcInner<[u8]>>: UnsafeUnpin, *const ArcInner<Vec<Value>> is !null: UnsafeUnpin, PhantomData<ArcInner<Vec<Value>>>: UnsafeUnpin, *const ArcInner<Inner<Value>> is !null: UnsafeUnpin, PhantomData<ArcInner<Inner<Value>>>: UnsafeUnpin, *const ArcInner<Inner<(Value, Value)>> is !null: UnsafeUnpin, PhantomData<ArcInner<Inner<(Value, Value)>>>: UnsafeUnpin, *const ArcInner<Inner<Member>> is !null: UnsafeUnpin, PhantomData<ArcInner<Inner<Member>>>: UnsafeUnpin, *const ArcInner<[Value]> is !null: UnsafeUnpin, PhantomData<ArcInner<[Value]>>: UnsafeUnpin, *const ArcInner<RecordShape> is !null: UnsafeUnpin, PhantomData<ArcInner<RecordShape>>: UnsafeUnpin, *const ArcInner<EnumShape> is !null: UnsafeUnpin, PhantomData<ArcInner<EnumShape>>: UnsafeUnpin, *const ArcInner<dyn Carry> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Carry>>: UnsafeUnpin, *const ArcInner<str> is !null: UnsafeUnpin, PhantomData<ArcInner<str>>: UnsafeUnpin,

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> Same for T

Source§

type Output = T

Should always be Self
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.