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 @tool 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§

impl Value

Source

pub fn depth_bound(&self) -> usize

How deeply the value nests, or more: a scalar is 0 deep and an aggregate one deeper than its deepest part, so [[1]] is 2 deep.

It costs constant time, since every aggregate records it when it is made. It is exact but for a list, a dictionary or a set that kept the measure of a larger one it was cut from — a part of a list, or a dictionary an entry was removed from — which may report more than it holds; Value::deeper_than is exact.

Source

pub fn may_hold_tasks(&self) -> bool

Whether some part of the value may be a task handle or a Native value, which may itself hold one; false means no part is either.

It costs constant time, and like Value::depth_bound may answer true for a list, dictionary or set that kept the measure of a larger one.

Source

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

Whether the value nests more than bound levels deep.

The answer is exact. It costs constant time when the measure each aggregate records settles it, and otherwise walks only the parts whose measures do not: those of a part cut from a deeper list. The walk is iterative, so a value nested deeper than the native stack is measured too.

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Self

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

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

impl FromIterator<Value> for List

Source§

fn from_iter<I: IntoIterator<Item = Value>>(items: I) -> Self

Creates a value from an iterator. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Value

§

impl !UnwindSafe for Value

§

impl Freeze for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnsafeUnpin for Value

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 = !

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.