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 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 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.
Source§impl MessageField for Value
impl MessageField for Value
impl StructuralPartialEq for Value
Auto Trait Implementations§
impl Freeze 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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more