#[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
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
impl Value
Sourcepub fn ty(&self) -> Ty
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.
Sourcepub fn matches(&self, ty: &Ty) -> bool
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).
Sourcepub fn matches_in(&self, ty: &Ty, types: &[TypeDecl]) -> bool
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).
Sourcepub fn approx_bytes(&self) -> usize
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,enumandOptionare 24 + the sum of their contents.
Sourcepub fn to_repl_text(&self) -> String
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 Debug for Value
structs and enums are shown with their fields, without showing the inner Arc (Struct { ty, fields }).
impl Debug for Value
structs and enums are shown with their fields, without showing the inner Arc (Struct { ty, fields }).