Enum Json

Source
pub enum Json {
    Array(Box<[Json]>),
    Object(Map<Box<str>, Json>),
    String(Box<str>),
    Number(f64),
    True,
    False,
    Null,
}
Expand description

Represents a JSON object

Variants§

§

Array(Box<[Json]>)

§

Object(Map<Box<str>, Json>)

§

String(Box<str>)

§

Number(f64)

§

True

§

False

§

Null

Implementations§

Source§

impl Json

Source

pub fn deserialize(text: impl AsRef<str>) -> Result<Json, Error>

Deserializes the given string into a Json object

§Configuration used

max_depth = u32::MAX

recover_from_errors = false

Source

pub fn deserialize_with_config( text: impl AsRef<str>, conf: JsonConfig, ) -> Result<Json, Error>

Deserializes the given string into a Json object using the given JsonConfig

Source

pub fn serialize(&self, out: &mut dyn Write) -> Result

Serializes the JSON object into a fmt::Write

Source

pub fn get(&self, key: impl AsRef<str>) -> Option<&Json>

Attempts to get a value of the given json object. If the json enum is not an Object variant, or if it doesn’t contain the key, returns None

Source

pub fn get_mut(&mut self, key: impl AsRef<str>) -> Option<&mut Json>

Same as get, but with a mutable reference

Source

pub fn nth(&self, i: usize) -> Option<&Json>

Attempts to get a value of the given json array. If the json enum is not an Array variant, or if it doesn’t contain the key, returns None

Source

pub fn nth_mut(&mut self, i: usize) -> Option<&mut Json>

Same as nth, but with a mutable reference

Source

pub const fn number(&self) -> Option<f64>

Attempts to get the inner Number of the json object, if it is a Number variant

Source

pub const fn expect_number(&self) -> f64

Expects the json object to be a Number variant

§Panics

If the json object is not a Number variant

Source

pub const fn number_mut(&mut self) -> Option<&mut f64>

Attempts to get a mutable reference to the inner Number of the json object, if it is a Number variant

Source

pub const fn expect_number_mut(&mut self) -> &mut f64

Expects the json object to be a Number variant and gets a mutable reference to the inner number.

§Panics

If the json object is not a Number variant

Source

pub const fn string(&self) -> Option<&str>

Attempts to get the inner String of the json object, if it is a String variant

Source

pub const fn expect_string(&self) -> &str

Expects the json object to be a String variant

§Panics

If the json object is not a String variant

Source

pub const fn string_mut(&mut self) -> Option<&mut str>

Attempts to get a mutable reference to the inner String of the json object, if it is a String variant

Source

pub const fn expect_string_mut(&mut self) -> &mut str

Expects the json object to be a String variant and gets a reference to the inner string

§Panics

If the json object is not a String variant

Source

pub const fn object(&self) -> Option<&Map<Box<str>, Json>>

Attempts to get the inner Object of the json object, if it is an Object variant

Source

pub const fn expect_object(&self) -> &Map<Box<str>, Json>

Expects the json object to be a Object variant and gets a reference to the inner object

§Panics

If the json object is not a Object variant

Source

pub const fn object_mut(&mut self) -> Option<&mut Map<Box<str>, Json>>

Attempts to get a mutable reference to the inner Object of the json element, if it is an Object variant

Source

pub const fn expect_object_mut(&mut self) -> &mut Map<Box<str>, Json>

Expects the json object to be a Object variant and gets a mutable reference to the inner object

§Panics

If the json object is not a Object variant

Source

pub const fn array(&self) -> Option<&[Json]>

Attempts to get the inner Array of the json object, if it is an Array variant

Source

pub const fn expect_array(&self) -> &[Json]

Expects the json object to be a Array variant

§Panics

If the json object is not a Array variant

Source

pub const fn array_mut(&mut self) -> Option<&mut [Json]>

Attempts to get the inner Array of the json object, if it is an Array variant

Source

pub const fn expect_array_mut(&mut self) -> &mut [Json]

Expects the json object to be a Array variant

§Panics

If the json object is not a Array variant

Source

pub const fn boolean(&self) -> Option<bool>

Attempts to get the inner boolean value of the json object, if it is a True or False variant

Source

pub const fn expect_boolean(&self) -> bool

Expects the json object to be a True or False variant

§Panics

If the json object is not a True or False variant

Source

pub const fn is_null(&self) -> bool

Returns true if the json is a Nil variant

Trait Implementations§

Source§

impl Add<f32> for Json

Source§

type Output = Json

The resulting type after applying the + operator.
Source§

fn add(self, rhs: f32) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<f64> for Json

Source§

type Output = Json

The resulting type after applying the + operator.
Source§

fn add(self, rhs: f64) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<i16> for Json

Source§

type Output = Json

The resulting type after applying the + operator.
Source§

fn add(self, rhs: i16) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<i32> for Json

Source§

type Output = Json

The resulting type after applying the + operator.
Source§

fn add(self, rhs: i32) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<u16> for Json

Source§

type Output = Json

The resulting type after applying the + operator.
Source§

fn add(self, rhs: u16) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<u8> for Json

Source§

type Output = Json

The resulting type after applying the + operator.
Source§

fn add(self, rhs: u8) -> Self::Output

Performs the + operation. Read more
Source§

impl AddAssign<f32> for Json

Source§

fn add_assign(&mut self, rhs: f32)

Performs the += operation. Read more
Source§

impl AddAssign<f64> for Json

Source§

fn add_assign(&mut self, rhs: f64)

Performs the += operation. Read more
Source§

impl AddAssign<i16> for Json

Source§

fn add_assign(&mut self, rhs: i16)

Performs the += operation. Read more
Source§

impl AddAssign<i32> for Json

Source§

fn add_assign(&mut self, rhs: i32)

Performs the += operation. Read more
Source§

impl AddAssign<u16> for Json

Source§

fn add_assign(&mut self, rhs: u16)

Performs the += operation. Read more
Source§

impl AddAssign<u8> for Json

Source§

fn add_assign(&mut self, rhs: u8)

Performs the += operation. Read more
Source§

impl Debug for Json

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Json

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Div<f32> for Json

Source§

type Output = Json

The resulting type after applying the / operator.
Source§

fn div(self, rhs: f32) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<f64> for Json

Source§

type Output = Json

The resulting type after applying the / operator.
Source§

fn div(self, rhs: f64) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<i16> for Json

Source§

type Output = Json

The resulting type after applying the / operator.
Source§

fn div(self, rhs: i16) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<i32> for Json

Source§

type Output = Json

The resulting type after applying the / operator.
Source§

fn div(self, rhs: i32) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<u16> for Json

Source§

type Output = Json

The resulting type after applying the / operator.
Source§

fn div(self, rhs: u16) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<u8> for Json

Source§

type Output = Json

The resulting type after applying the / operator.
Source§

fn div(self, rhs: u8) -> Self::Output

Performs the / operation. Read more
Source§

impl DivAssign<f32> for Json

Source§

fn div_assign(&mut self, rhs: f32)

Performs the /= operation. Read more
Source§

impl DivAssign<f64> for Json

Source§

fn div_assign(&mut self, rhs: f64)

Performs the /= operation. Read more
Source§

impl DivAssign<i16> for Json

Source§

fn div_assign(&mut self, rhs: i16)

Performs the /= operation. Read more
Source§

impl DivAssign<i32> for Json

Source§

fn div_assign(&mut self, rhs: i32)

Performs the /= operation. Read more
Source§

impl DivAssign<u16> for Json

Source§

fn div_assign(&mut self, rhs: u16)

Performs the /= operation. Read more
Source§

impl DivAssign<u8> for Json

Source§

fn div_assign(&mut self, rhs: u8)

Performs the /= operation. Read more
Source§

impl<'a> From<&'a str> for Json

Source§

fn from(value: &'a str) -> Self

Converts to this type from the input type.
Source§

impl From<Box<str>> for Json

Source§

fn from(value: Box<str>) -> Self

Converts to this type from the input type.
Source§

impl From<HashMap<Box<str>, Json>> for Json

Source§

fn from(value: Map<Box<str>, Json>) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Json

Source§

fn from(value: String) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<Json>> for Json

Source§

fn from(value: Vec<Json>) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for Json

Source§

fn from(value: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for Json

Source§

fn from(value: f32) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Json

Source§

fn from(value: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i16> for Json

Source§

fn from(value: i16) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Json

Source§

fn from(value: i32) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for Json

Source§

fn from(value: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for Json

Source§

fn from(value: u8) -> Self

Converts to this type from the input type.
Source§

impl Index<&str> for Json

Source§

type Output = Json

The returned type after indexing.
Source§

fn index(&self, index: &str) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<usize> for Json

Source§

type Output = Json

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<&str> for Json

Source§

fn index_mut(&mut self, index: &str) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<usize> for Json

Source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl Mul<f32> for Json

Source§

type Output = Json

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f32) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<f64> for Json

Source§

type Output = Json

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f64) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<i16> for Json

Source§

type Output = Json

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: i16) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<i32> for Json

Source§

type Output = Json

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: i32) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<u16> for Json

Source§

type Output = Json

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: u16) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<u8> for Json

Source§

type Output = Json

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: u8) -> Self::Output

Performs the * operation. Read more
Source§

impl MulAssign<f32> for Json

Source§

fn mul_assign(&mut self, rhs: f32)

Performs the *= operation. Read more
Source§

impl MulAssign<f64> for Json

Source§

fn mul_assign(&mut self, rhs: f64)

Performs the *= operation. Read more
Source§

impl MulAssign<i16> for Json

Source§

fn mul_assign(&mut self, rhs: i16)

Performs the *= operation. Read more
Source§

impl MulAssign<i32> for Json

Source§

fn mul_assign(&mut self, rhs: i32)

Performs the *= operation. Read more
Source§

impl MulAssign<u16> for Json

Source§

fn mul_assign(&mut self, rhs: u16)

Performs the *= operation. Read more
Source§

impl MulAssign<u8> for Json

Source§

fn mul_assign(&mut self, rhs: u8)

Performs the *= operation. Read more
Source§

impl PartialEq for Json

Source§

fn eq(&self, other: &Json) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Sub<f32> for Json

Source§

type Output = Json

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: f32) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<f64> for Json

Source§

type Output = Json

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: f64) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<i16> for Json

Source§

type Output = Json

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: i16) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<i32> for Json

Source§

type Output = Json

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: i32) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<u16> for Json

Source§

type Output = Json

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: u16) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<u8> for Json

Source§

type Output = Json

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: u8) -> Self::Output

Performs the - operation. Read more
Source§

impl SubAssign<f32> for Json

Source§

fn sub_assign(&mut self, rhs: f32)

Performs the -= operation. Read more
Source§

impl SubAssign<f64> for Json

Source§

fn sub_assign(&mut self, rhs: f64)

Performs the -= operation. Read more
Source§

impl SubAssign<i16> for Json

Source§

fn sub_assign(&mut self, rhs: i16)

Performs the -= operation. Read more
Source§

impl SubAssign<i32> for Json

Source§

fn sub_assign(&mut self, rhs: i32)

Performs the -= operation. Read more
Source§

impl SubAssign<u16> for Json

Source§

fn sub_assign(&mut self, rhs: u16)

Performs the -= operation. Read more
Source§

impl SubAssign<u8> for Json

Source§

fn sub_assign(&mut self, rhs: u8)

Performs the -= operation. Read more
Source§

impl StructuralPartialEq for Json

Auto Trait Implementations§

§

impl Freeze for Json

§

impl RefUnwindSafe for Json

§

impl Send for Json

§

impl Sync for Json

§

impl Unpin for Json

§

impl UnwindSafe for Json

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.