pub enum SerializedValue {
Null,
Bool(bool),
Int(i64),
Float(f64),
Str(String),
Bytes(Vec<u8>),
List(Vec<SerializedValue>),
Map(HashMap<String, SerializedValue>),
}Expand description
A generic serialized value, analogous to serde_json::Value.
Variants§
Null
Bool(bool)
Int(i64)
Float(f64)
Str(String)
Bytes(Vec<u8>)
List(Vec<SerializedValue>)
Map(HashMap<String, SerializedValue>)
Implementations§
Source§impl SerializedValue
impl SerializedValue
pub fn null() -> Self
pub fn bool(b: bool) -> Self
pub fn int(i: i64) -> Self
pub fn float(f: f64) -> Self
pub fn str(s: impl Into<String>) -> Self
pub fn bytes(b: Vec<u8>) -> Self
pub fn list(v: Vec<SerializedValue>) -> Self
pub fn map(m: HashMap<String, SerializedValue>) -> Self
pub fn empty_map() -> Self
pub fn empty_list() -> Self
pub fn as_bool(&self) -> Option<bool>
pub fn as_int(&self) -> Option<i64>
pub fn as_float(&self) -> Option<f64>
pub fn as_str(&self) -> Option<&str>
pub fn as_bytes(&self) -> Option<&[u8]>
pub fn as_list(&self) -> Option<&[SerializedValue]>
pub fn as_map(&self) -> Option<&HashMap<String, SerializedValue>>
pub fn as_map_mut(&mut self) -> Option<&mut HashMap<String, SerializedValue>>
pub fn is_null(&self) -> bool
Sourcepub fn get(&self, key: &str) -> Option<&SerializedValue>
pub fn get(&self, key: &str) -> Option<&SerializedValue>
Get a value from a Map by key.
Sourcepub fn index(&self, i: usize) -> Option<&SerializedValue>
pub fn index(&self, i: usize) -> Option<&SerializedValue>
Get a value from a List by index.
Sourcepub fn insert(&mut self, key: impl Into<String>, value: SerializedValue) -> bool
pub fn insert(&mut self, key: impl Into<String>, value: SerializedValue) -> bool
Insert a key-value pair into a Map. Returns false if self is not a Map.
Sourcepub fn push(&mut self, value: SerializedValue) -> bool
pub fn push(&mut self, value: SerializedValue) -> bool
Push a value into a List. Returns false if self is not a List.
Sourcepub fn type_name(&self) -> &'static str
pub fn type_name(&self) -> &'static str
The variant name as a static string (for error messages).
Sourcepub fn to_json_string(&self) -> String
pub fn to_json_string(&self) -> String
Encode to a JSON string. Bytes are encoded as a base64-like hex string.
Sourcepub fn from_json_str(s: &str) -> Result<Self, DeserializeError>
pub fn from_json_str(s: &str) -> Result<Self, DeserializeError>
Parse a JSON string into a SerializedValue.
Trait Implementations§
Source§impl Clone for SerializedValue
impl Clone for SerializedValue
Source§fn clone(&self) -> SerializedValue
fn clone(&self) -> SerializedValue
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SerializedValue
impl Debug for SerializedValue
Source§impl Default for SerializedValue
impl Default for SerializedValue
Source§impl PartialEq for SerializedValue
impl PartialEq for SerializedValue
impl StructuralPartialEq for SerializedValue
Auto Trait Implementations§
impl Freeze for SerializedValue
impl RefUnwindSafe for SerializedValue
impl Send for SerializedValue
impl Sync for SerializedValue
impl Unpin for SerializedValue
impl UnsafeUnpin for SerializedValue
impl UnwindSafe for SerializedValue
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.