pub enum CanonicalJsonValue {
Null,
Bool(bool),
Integer(Int),
String(String),
Array(Vec<CanonicalJsonValue>),
Object(BTreeMap<String, CanonicalJsonValue>),
}
canonical-json
only.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(BTreeMap<String, CanonicalJsonValue>)
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§
Source§impl 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<&BTreeMap<String, CanonicalJsonValue>>
pub fn as_object(&self) -> Option<&BTreeMap<String, CanonicalJsonValue>>
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 BTreeMap<String, CanonicalJsonValue>>
pub fn as_object_mut( &mut self, ) -> Option<&mut BTreeMap<String, CanonicalJsonValue>>
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§
Source§impl Clone for CanonicalJsonValue
impl Clone for CanonicalJsonValue
Source§fn clone(&self) -> CanonicalJsonValue
fn clone(&self) -> CanonicalJsonValue
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for CanonicalJsonValue
impl Debug for CanonicalJsonValue
Source§impl Default for CanonicalJsonValue
impl Default for CanonicalJsonValue
Source§fn default() -> CanonicalJsonValue
fn default() -> CanonicalJsonValue
Source§impl<'de> Deserialize<'de> for CanonicalJsonValue
impl<'de> Deserialize<'de> for CanonicalJsonValue
Source§fn deserialize<D>(
deserializer: D,
) -> Result<CanonicalJsonValue, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<CanonicalJsonValue, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl Display for CanonicalJsonValue
impl Display for CanonicalJsonValue
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>
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}
.
Source§impl From<&str> for CanonicalJsonValue
impl From<&str> for CanonicalJsonValue
Source§fn from(val: &str) -> CanonicalJsonValue
fn from(val: &str) -> CanonicalJsonValue
Source§impl From<BTreeMap<String, CanonicalJsonValue>> for CanonicalJsonValue
impl From<BTreeMap<String, CanonicalJsonValue>> for CanonicalJsonValue
Source§fn from(val: BTreeMap<String, CanonicalJsonValue>) -> CanonicalJsonValue
fn from(val: BTreeMap<String, CanonicalJsonValue>) -> CanonicalJsonValue
Source§impl From<CanonicalJsonValue> for Value
impl From<CanonicalJsonValue> for Value
Source§fn from(val: CanonicalJsonValue) -> Value
fn from(val: CanonicalJsonValue) -> Value
Source§impl From<Int> for CanonicalJsonValue
impl From<Int> for CanonicalJsonValue
Source§fn from(val: Int) -> CanonicalJsonValue
fn from(val: Int) -> CanonicalJsonValue
Source§impl From<String> for CanonicalJsonValue
impl From<String> for CanonicalJsonValue
Source§fn from(val: String) -> CanonicalJsonValue
fn from(val: String) -> CanonicalJsonValue
Source§impl From<UInt> for CanonicalJsonValue
impl From<UInt> for CanonicalJsonValue
Source§fn from(value: UInt) -> CanonicalJsonValue
fn from(value: UInt) -> CanonicalJsonValue
Source§impl From<Vec<CanonicalJsonValue>> for CanonicalJsonValue
impl From<Vec<CanonicalJsonValue>> for CanonicalJsonValue
Source§fn from(val: Vec<CanonicalJsonValue>) -> CanonicalJsonValue
fn from(val: Vec<CanonicalJsonValue>) -> CanonicalJsonValue
Source§impl From<bool> for CanonicalJsonValue
impl From<bool> for CanonicalJsonValue
Source§fn from(val: bool) -> CanonicalJsonValue
fn from(val: bool) -> CanonicalJsonValue
Source§impl PartialEq<&str> for CanonicalJsonValue
impl PartialEq<&str> for CanonicalJsonValue
Source§impl PartialEq<BTreeMap<String, CanonicalJsonValue>> for CanonicalJsonValue
impl PartialEq<BTreeMap<String, CanonicalJsonValue>> for CanonicalJsonValue
Source§impl PartialEq<CanonicalJsonValue> for &str
impl PartialEq<CanonicalJsonValue> for &str
Source§impl PartialEq<CanonicalJsonValue> for Int
impl PartialEq<CanonicalJsonValue> for Int
Source§impl PartialEq<CanonicalJsonValue> for String
impl PartialEq<CanonicalJsonValue> for String
Source§impl PartialEq<CanonicalJsonValue> for Vec<CanonicalJsonValue>
impl PartialEq<CanonicalJsonValue> for Vec<CanonicalJsonValue>
Source§impl PartialEq<Int> for CanonicalJsonValue
impl PartialEq<Int> for CanonicalJsonValue
Source§impl PartialEq<String> for CanonicalJsonValue
impl PartialEq<String> for CanonicalJsonValue
Source§impl PartialEq<Vec<CanonicalJsonValue>> for CanonicalJsonValue
impl PartialEq<Vec<CanonicalJsonValue>> for CanonicalJsonValue
Source§impl PartialEq<bool> for CanonicalJsonValue
impl PartialEq<bool> for CanonicalJsonValue
Source§impl PartialEq for CanonicalJsonValue
impl PartialEq for CanonicalJsonValue
Source§impl Serialize for CanonicalJsonValue
impl Serialize for CanonicalJsonValue
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Source§impl TryFrom<Value> for CanonicalJsonValue
impl TryFrom<Value> for CanonicalJsonValue
Source§type Error = CanonicalJsonError
type Error = CanonicalJsonError
Source§fn try_from(
val: Value,
) -> Result<CanonicalJsonValue, <CanonicalJsonValue as TryFrom<Value>>::Error>
fn try_from( val: Value, ) -> Result<CanonicalJsonValue, <CanonicalJsonValue as TryFrom<Value>>::Error>
impl Eq for CanonicalJsonValue
impl StructuralPartialEq for CanonicalJsonValue
Auto Trait Implementations§
impl Freeze for CanonicalJsonValue
impl RefUnwindSafe for CanonicalJsonValue
impl Send for CanonicalJsonValue
impl Sync for CanonicalJsonValue
impl Unpin for CanonicalJsonValue
impl UnwindSafe for CanonicalJsonValue
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> CompatExt for T
impl<T> CompatExt for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
Source§fn consume_handle(handle: Handle) -> Arc<T>
fn consume_handle(handle: Handle) -> Arc<T>
Arc<>
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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