pub enum Value {
Null,
Bool(bool),
Int(i64),
Float(f64),
Str(String),
List(Vec<Value>),
Map(Vec<(String, Value)>),
}Expand description
A dynamically typed value: null, bool, int, float, string, list or an ordered string-keyed map. See the module docs for an example.
Variants§
Implementations§
Source§impl Value
impl Value
Sourcepub fn owns_buffers(&self) -> bool
pub fn owns_buffers(&self) -> bool
Whether the value holds a heap buffer — a string, a list or a map —
that Clone::clone_from can write another like it into.
Sourcepub fn map(entries: impl IntoIterator<Item = (&'static str, Value)>) -> Value
pub fn map(entries: impl IntoIterator<Item = (&'static str, Value)>) -> Value
A map from (key, value) pairs, in the order given.
Sourcepub fn get(&self, key: &str) -> Option<&Value>
pub fn get(&self, key: &str) -> Option<&Value>
The entry under key of a map; None for a missing key or a
value that is not a map.
pub fn as_str(&self) -> Option<&str>
pub fn as_list(&self) -> Option<&[Value]>
pub fn as_bool(&self) -> Option<bool>
Sourcepub fn get_str(&self, key: &str) -> Option<&str>
pub fn get_str(&self, key: &str) -> Option<&str>
get(key) then as_str: a map entry read as a string.
Source§impl Value
impl Value
Sourcepub fn opt<T>(v: Option<T>, f: impl FnOnce(T) -> Value) -> Value
pub fn opt<T>(v: Option<T>, f: impl FnOnce(T) -> Value) -> Value
An Option as the value or Null: a readback keeps every key,
so a reader destructures a stable shape.
pub fn opt_str(s: &Option<String>) -> Value
pub fn opt_float(v: Option<f32>) -> Value
pub fn opt_usize(v: Option<usize>) -> Value
pub fn opt_bool(v: Option<bool>) -> Value
pub fn list(items: impl IntoIterator<Item = Value>) -> Value
pub fn floats(items: &[f32]) -> Value
Trait Implementations§
Source§impl Clone for Value
impl Clone for Value
Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Into the buffers self already has where the two are the same
shape — a string into a string, a map into a map, entry by entry —
so a value written over with another like it allocates nothing:
what the core does with every click message every frame (backlog
F281). The result is source.clone() either way.
Source§impl From<&Value> for Value
A copy, so ev.message::<Value>() and ev.split::<Value>() read an
event’s message untyped.
impl From<&Value> for Value
A copy, so ev.message::<Value>() and ev.split::<Value>() read an
event’s message untyped.
Source§impl From<usize> for Value
An index or a count. One past i64::MAX cannot be a payload’s number,
so it saturates there rather than wrapping negative.
impl From<usize> for Value
An index or a count. One past i64::MAX cannot be a payload’s number,
so it saturates there rather than wrapping negative.