Enum Value
pub enum Value {
None,
Int(i128),
Float(f64),
String(String),
Address(Address),
Struct(Box<IndexMap<String, Value>>),
Array(Vec<Value>),
}
Expand description
A dynamically typed value.
Variants§
None
Represents the lack of a value.
For example, when evaluating a data path and ?
is used on a null pointer,
Value::None
is returned for the entire path.
Int(i128)
An integer value, regardless of the underlying IntType
size.
Float(f64)
A float value, regardless of the underlying FloatType
size.
String(String)
A string value.
Address(Address)
An address value.
Struct(Box<IndexMap<String, Value>>)
A struct value.
If a field’s name is present in the original struct definition, it will match the
name used here. Anonymous fields will be given a name, typically __anon
.
Array(Vec<Value>)
An array value.
Implementations§
§impl Value
impl Value
pub fn as_none(&self)
pub fn as_none(&self)
Panic if the value is not Value::None
.
pub fn try_as_none(&self) -> Result<(), ValueTypeError>
pub fn try_as_none(&self) -> Result<(), ValueTypeError>
Return an error if the value is not Value::None
.
pub fn try_as_int(&self) -> Result<i128, ValueTypeError>
pub fn try_as_int(&self) -> Result<i128, ValueTypeError>
Convert the value to an int.
pub fn as_int_lenient(&self) -> i128
pub fn as_int_lenient(&self) -> i128
Convert the value to an int, allowing in-range floats that are integers.
Panics if the conversion fails.
pub fn try_as_int_lenient(&self) -> Result<i128, ValueTypeError>
pub fn try_as_int_lenient(&self) -> Result<i128, ValueTypeError>
Convert the value to an int, allowing in-range floats that are integers.
pub fn try_as_usize(&self) -> Result<usize, ValueTypeError>
pub fn try_as_usize(&self) -> Result<usize, ValueTypeError>
Convert the value to a usize.
pub fn try_as_float(&self) -> Result<f64, ValueTypeError>
pub fn try_as_float(&self) -> Result<f64, ValueTypeError>
Convert the value to a float.
pub fn as_float_lenient(&self) -> f64
pub fn as_float_lenient(&self) -> f64
Convert the value to a usize, allowing in-range integers.
Panics on failure.
pub fn try_as_float_lenient(&self) -> Result<f64, ValueTypeError>
pub fn try_as_float_lenient(&self) -> Result<f64, ValueTypeError>
Convert the value to a float, allowing in-range integers.
pub fn as_f32(&self) -> f32
pub fn as_f32(&self) -> f32
Convert the value to a float, and then truncate to an f32, panicking on failure.
pub fn try_as_f32(&self) -> Result<f32, ValueTypeError>
pub fn try_as_f32(&self) -> Result<f32, ValueTypeError>
Convert the value to a float and then truncate to an f32.
pub fn try_as_str(&self) -> Result<&str, ValueTypeError>
pub fn try_as_str(&self) -> Result<&str, ValueTypeError>
Convert the value to a string.
pub fn as_address(&self) -> Address
pub fn as_address(&self) -> Address
Convert the value to an address, panicking on failure.
pub fn try_as_address(&self) -> Result<Address, ValueTypeError>
pub fn try_as_address(&self) -> Result<Address, ValueTypeError>
Convert the value to an address.
pub fn as_struct(&self) -> &IndexMap<String, Value>
pub fn as_struct(&self) -> &IndexMap<String, Value>
Convert the value to a struct and return its fields, panicking on failure.
pub fn try_as_struct(&self) -> Result<&IndexMap<String, Value>, ValueTypeError>
pub fn try_as_struct(&self) -> Result<&IndexMap<String, Value>, ValueTypeError>
Convert the value to a struct and return its fields.
pub fn field(&self, name: &str) -> &Value
pub fn field(&self, name: &str) -> &Value
Convert the value to a struct and look up the field with the given name, panicking on failure.
pub fn try_field(&self, name: &str) -> Result<&Value, ValueTypeError>
pub fn try_field(&self, name: &str) -> Result<&Value, ValueTypeError>
Convert the value to a struct and look up the field with the given name.
pub fn as_array(&self) -> &[Value]
pub fn as_array(&self) -> &[Value]
Convert the value to an array and return its elements, panicking on failure.
pub fn try_as_array(&self) -> Result<&[Value], ValueTypeError>
pub fn try_as_array(&self) -> Result<&[Value], ValueTypeError>
Convert the value to an array and return its elements.
pub fn as_array_with_len(&self, length: usize) -> &[Value]
pub fn as_array_with_len(&self, length: usize) -> &[Value]
Convert the value to an array and return its elements, panicking on failure.
pub fn try_as_array_with_len(
&self,
length: usize,
) -> Result<&[Value], ValueTypeError>
pub fn try_as_array_with_len( &self, length: usize, ) -> Result<&[Value], ValueTypeError>
Convert the value to an array and return its elements.
pub fn as_i16_3(&self) -> [i16; 3]
pub fn as_i16_3(&self) -> [i16; 3]
Convert the value to an array of three i16s, panicking on failure.
pub fn try_as_i16_3(&self) -> Result<[i16; 3], ValueTypeError>
pub fn try_as_i16_3(&self) -> Result<[i16; 3], ValueTypeError>
Convert the value to an array of three i16s.
pub fn as_f32_3(&self) -> [f32; 3]
pub fn as_f32_3(&self) -> [f32; 3]
Convert the value to an array of three f32s, panicking on failure.
pub fn try_as_f32_3(&self) -> Result<[f32; 3], ValueTypeError>
pub fn try_as_f32_3(&self) -> Result<[f32; 3], ValueTypeError>
Convert the value to an array of three f32s.