Enum ruma_common::serde::CanonicalJsonValue
source · [−]pub enum CanonicalJsonValue {
Null,
Bool(bool),
Integer(Int),
String(String),
Array(Vec<CanonicalJsonValue>),
Object(Object),
}
Expand description
Represents a canonical JSON value as per the Matrix specification.
Variants
Null
Represents a JSON null value.
let v: CanonicalJsonValue = json!(null).try_into().unwrap();
Bool(bool)
Represents a JSON boolean.
let v: CanonicalJsonValue = json!(true).try_into().unwrap();
Integer(Int)
Represents a JSON integer.
let v: CanonicalJsonValue = json!(12).try_into().unwrap();
String(String)
Represents a JSON string.
let v: CanonicalJsonValue = json!("a string").try_into().unwrap();
Array(Vec<CanonicalJsonValue>)
Represents a JSON array.
let v: CanonicalJsonValue = json!(["an", "array"]).try_into().unwrap();
Object(Object)
Represents a JSON object.
The map is backed by a BTreeMap to guarantee the sorting of keys.
let v: CanonicalJsonValue = json!({ "an": "object" }).try_into().unwrap();
Implementations
sourceimpl CanonicalJsonValue
impl CanonicalJsonValue
sourcepub fn as_bool(&self) -> Option<bool>
pub fn as_bool(&self) -> Option<bool>
If the CanonicalJsonValue
is a Bool
, return the inner value.
sourcepub fn as_integer(&self) -> Option<Int>
pub fn as_integer(&self) -> Option<Int>
If the CanonicalJsonValue
is an Integer
, return the inner value.
sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
If the CanonicalJsonValue
is a String
, return a reference to the inner value.
sourcepub fn as_array(&self) -> Option<&[CanonicalJsonValue]>
pub fn as_array(&self) -> Option<&[CanonicalJsonValue]>
If the CanonicalJsonValue
is an Array
, return a reference to the inner value.
sourcepub fn as_object(&self) -> Option<&Object>
pub fn as_object(&self) -> Option<&Object>
If the CanonicalJsonValue
is an Object
, return a reference to the inner value.
sourcepub fn as_array_mut(&mut self) -> Option<&mut Vec<CanonicalJsonValue>>
pub fn as_array_mut(&mut self) -> Option<&mut Vec<CanonicalJsonValue>>
If the CanonicalJsonValue
is an Array
, return a mutable reference to the inner value.
sourcepub fn as_object_mut(&mut self) -> Option<&mut Object>
pub fn as_object_mut(&mut self) -> Option<&mut Object>
If the CanonicalJsonValue
is an Object
, return a mutable reference to the inner value.
sourcepub fn is_integer(&self) -> bool
pub fn is_integer(&self) -> bool
Returns true
if the CanonicalJsonValue
is an Integer
.
Trait Implementations
sourceimpl Clone for CanonicalJsonValue
impl Clone for CanonicalJsonValue
sourcefn clone(&self) -> CanonicalJsonValue
fn clone(&self) -> CanonicalJsonValue
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for CanonicalJsonValue
impl Debug for CanonicalJsonValue
sourceimpl Default for CanonicalJsonValue
impl Default for CanonicalJsonValue
sourceimpl<'de> Deserialize<'de> for CanonicalJsonValue
impl<'de> Deserialize<'de> for CanonicalJsonValue
sourcefn deserialize<D>(deserializer: D) -> Result<CanonicalJsonValue, D::Error> where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<CanonicalJsonValue, D::Error> where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl Display for CanonicalJsonValue
impl Display for CanonicalJsonValue
sourcefn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Display this value as a string.
This Display
implementation is intentionally unaffected by any formatting parameters,
because adding extra whitespace or otherwise pretty-printing it would make it not the
canonical form anymore.
If you want to pretty-print a CanonicalJsonValue
for debugging purposes, use
one of serde_json::{to_string_pretty, to_vec_pretty, to_writer_pretty}
.
sourceimpl From<BTreeMap<String, CanonicalJsonValue, Global>> for CanonicalJsonValue
impl From<BTreeMap<String, CanonicalJsonValue, Global>> for CanonicalJsonValue
sourceimpl From<CanonicalJsonValue> for JsonValue
impl From<CanonicalJsonValue> for JsonValue
sourcefn from(val: CanonicalJsonValue) -> Self
fn from(val: CanonicalJsonValue) -> Self
Converts to this type from the input type.
sourceimpl From<Int> for CanonicalJsonValue
impl From<Int> for CanonicalJsonValue
sourceimpl From<String> for CanonicalJsonValue
impl From<String> for CanonicalJsonValue
sourceimpl From<Vec<CanonicalJsonValue, Global>> for CanonicalJsonValue
impl From<Vec<CanonicalJsonValue, Global>> for CanonicalJsonValue
sourcefn from(val: Vec<CanonicalJsonValue>) -> Self
fn from(val: Vec<CanonicalJsonValue>) -> Self
Converts to this type from the input type.
sourceimpl From<bool> for CanonicalJsonValue
impl From<bool> for CanonicalJsonValue
sourceimpl PartialEq<BTreeMap<String, CanonicalJsonValue, Global>> for CanonicalJsonValue
impl PartialEq<BTreeMap<String, CanonicalJsonValue, Global>> for CanonicalJsonValue
sourceimpl PartialEq<CanonicalJsonValue> for CanonicalJsonValue
impl PartialEq<CanonicalJsonValue> for CanonicalJsonValue
sourcefn eq(&self, other: &CanonicalJsonValue) -> bool
fn eq(&self, other: &CanonicalJsonValue) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &CanonicalJsonValue) -> bool
fn ne(&self, other: &CanonicalJsonValue) -> bool
This method tests for !=
.
sourceimpl PartialEq<CanonicalJsonValue> for bool
impl PartialEq<CanonicalJsonValue> for bool
sourceimpl PartialEq<CanonicalJsonValue> for Int
impl PartialEq<CanonicalJsonValue> for Int
sourceimpl PartialEq<CanonicalJsonValue> for String
impl PartialEq<CanonicalJsonValue> for String
sourceimpl PartialEq<CanonicalJsonValue> for Vec<CanonicalJsonValue>
impl PartialEq<CanonicalJsonValue> for Vec<CanonicalJsonValue>
sourceimpl PartialEq<CanonicalJsonValue> for Object
impl PartialEq<CanonicalJsonValue> for Object
sourceimpl PartialEq<Int> for CanonicalJsonValue
impl PartialEq<Int> for CanonicalJsonValue
sourceimpl PartialEq<String> for CanonicalJsonValue
impl PartialEq<String> for CanonicalJsonValue
sourceimpl PartialEq<Vec<CanonicalJsonValue, Global>> for CanonicalJsonValue
impl PartialEq<Vec<CanonicalJsonValue, Global>> for CanonicalJsonValue
sourceimpl PartialEq<bool> for CanonicalJsonValue
impl PartialEq<bool> for CanonicalJsonValue
sourceimpl Serialize for CanonicalJsonValue
impl Serialize for CanonicalJsonValue
sourceimpl TryFrom<Value> for CanonicalJsonValue
impl TryFrom<Value> for CanonicalJsonValue
impl Eq for CanonicalJsonValue
impl StructuralEq for CanonicalJsonValue
impl StructuralPartialEq for CanonicalJsonValue
Auto Trait Implementations
impl RefUnwindSafe for CanonicalJsonValue
impl Send for CanonicalJsonValue
impl Sync for CanonicalJsonValue
impl Unpin for CanonicalJsonValue
impl UnwindSafe for CanonicalJsonValue
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more