pub enum Value {
Bool(bool),
Int(i64),
Str(String),
List(Vec<Value>),
Record(BTreeMap<String, Value>),
}Expand description
A value shaped by a Schema. Mirrors lattice_config::ConfigValue.
Record is a BTreeMap for the same reason the host’s is: a value written
in TOML (unordered) and the same value built from a struct must compare
equal, or “the same config” is two values.
§Examples
use lattice_plugin_sdk::shape::Value;
let v = Value::record([
("width".to_string(), Value::Int(80)),
("wrap".to_string(), Value::Bool(true)),
]);
assert_eq!(v.field("width").and_then(Value::as_int), Some(80));
// Accessors are kind-checked: the wrong kind is `None`, not a coercion.
assert_eq!(v.field("wrap").and_then(Value::as_int), None);
assert_eq!(v.kind_label(), "record");Variants§
Bool(bool)
A boolean leaf.
Int(i64)
An integer leaf.
Str(String)
A string leaf — also how a Schema::Enum member is carried.
List(Vec<Value>)
An ordered list of values.
Record(BTreeMap<String, Value>)
Named fields, key-ordered (see the type docs for why). An optional field that is absent has no entry at all.
Implementations§
Source§impl Value
impl Value
Sourcepub fn record(fields: impl IntoIterator<Item = (String, Value)>) -> Self
pub fn record(fields: impl IntoIterator<Item = (String, Value)>) -> Self
Build a Value::Record from (key, value) pairs. A repeated key keeps
the last value (it is collected into a BTreeMap).
Sourcepub fn kind_label(&self) -> &'static str
pub fn kind_label(&self) -> &'static str
The human name of this value’s kind — "boolean", "integer",
"string", "list" or "record" — as used in ShapeError messages
(expected integer, got string).
Sourcepub fn as_bool(&self) -> Option<bool>
pub fn as_bool(&self) -> Option<bool>
The boolean, if this is a Value::Bool; None for any other kind.
Sourcepub fn as_int(&self) -> Option<i64>
pub fn as_int(&self) -> Option<i64>
The integer, if this is a Value::Int; None for any other kind.
Sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
The string, if this is a Value::Str; None for any other kind.
Sourcepub fn as_list(&self) -> Option<&[Value]>
pub fn as_list(&self) -> Option<&[Value]>
The elements, if this is a Value::List; None for any other kind.