Skip to main content

Value

Enum Value 

Source
#[non_exhaustive]
pub enum Value { Unit, Int(i64), Float(f64), Bool(bool), Str(StrValue), Identity(Arc<Identity>), List(ListData), Map(MapData), Option(Option<Box<Value>>), Struct(Arc<StructValue>), Enum(Arc<EnumValue>), Fn(Arc<FnValue>), }
Expand description

A value.

== compares contents. maps are equal if they have the same values for the same keys, regardless of insertion order (other types are equal only if order and names match too).

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Unit

No return value.

§

Int(i64)

An integer.

§

Float(f64)

A floating point number. Finite, and never -0.0 (normalized to 0.0).

§

Bool(bool)

A boolean.

§

Str(StrValue)

A string. The contents are shared (cloning only copies the Arc; strings are never modified).

§

Identity(Arc<Identity>)

An Identity (shared; the contents live behind an Arc to keep Value small).

§

List(ListData)

list<T>. The elements are a ListData (cloning shares them; an update copies the contents if shared).

§

Map(MapData)

map<K, V>. Holds pairs of keys and values in insertion order (keys do not repeat).

§

Option(Option<Box<Value>>)

Option<T> (None is None).

§

Struct(Arc<StructValue>)

A struct value (shared; the contents live behind an Arc to keep Value small). To modify it, use Arc::make_mut, which copies first if shared.

§

Enum(Arc<EnumValue>)

An enum value (shared; the contents live behind an Arc to keep Value small). To modify it, use Arc::make_mut, which copies first if shared.

§

Fn(Arc<FnValue>)

A function value (a reference to a fn, or a closure made by a lambda). It does not go into saves, so it cannot be serialized.

Implementations§

Source§

impl Value

Source

pub fn ty(&self) -> Ty

The type of the value (as far as can be known). The element type of an empty list and the content type of None cannot be decided, so they are returned as (). Use Value::matches to check types.

Source

pub fn matches(&self, ty: &Ty) -> bool

Whether the value matches type ty (list and Option are checked down to their contents). For structs and enums, only the type name is checked (to check fields too, use Value::matches_in).

Source

pub fn matches_in(&self, ty: &Ty, types: &[TypeDecl]) -> bool

Whether the value matches type ty. For structs and enums declared in types, names and types of fields and arguments are checked too (without a declaration, only the type name).

Source

pub fn depth(&self) -> u32

The nesting depth of the value (scalars are 1).

Source

pub fn approx_bytes(&self) -> usize

An approximate size of the value (bytes). Used to check VmConfig::max_value_bytes. Scalars are 8, strings are length

  • 24, and list, struct, enum and Option are 24 + the sum of their contents.
Source

pub fn to_text(&self) -> String

The value as a string (used for ${expr} interpolation).

Source

pub fn to_repl_text(&self) -> String

The display string for the REPL and :vars (section 7.2.4 of spec/host/07-repl.md). Same as the ${expr} form (Value::to_text), except that str is enclosed in " including inside nesting (escaped with \", \\, \n, \t, \$), and Identity is written Identity { id: "…", name: "…" }.

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

structs and enums are shown with their fields, without showing the inner Arc (Struct { ty, fields }).

Source§

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

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

impl<'de> Deserialize<'de> for Value

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl FromIterator<Value> for ListData

Source§

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

Creates a value from an iterator. Read more
Source§

impl PartialEq for Value

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Serialize for Value

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Forget for Value

§

impl Freeze for Value

§

impl Move for Value

§

impl RefUnwindSafe for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnsafeUnpin for Value

§

impl UnwindSafe 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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.