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 compact JSON string.
Map keys come out sorted, so the same value always gives the same
text. JSON has no NaN or infinity: NaN is written as null and
infinities as the largest finite double, 1e+308 / -1e+308. Bytes are written as a lowercase
hex string.
Sourcepub fn to_json_value(&self) -> Value
pub fn to_json_value(&self) -> Value
Convert to a serde_json::Value, with the rules of
to_json_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.
Integers that fit in an i64 become Int; every other number
becomes Float. Hex strings stay Str, since JSON cannot say they
were bytes; Vec<u8> fields read them back through their own
Deserialize.
Sourcepub fn from_json_value(v: Value) -> Self
pub fn from_json_value(v: Value) -> Self
Convert from a serde_json::Value.
Trait Implementations§
Source§impl Clone for SerializedValue
impl Clone for SerializedValue
Source§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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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>
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>
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)
&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)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more