Enum Value

Source
pub enum Value {
    Null,
    Boolean(bool),
    Number(Number),
    String(String),
    Array(Vec<Value>),
    Object(ValueMap),
}
Expand description

JSON Value.

Variants§

§

Null

Null value.

null
§

Boolean(bool)

A boolean value.

true

or

false
§

Number(Number)

An f64 or i64 number.

3.14159265358979
§

String(String)

A UTF-8 encoded string.

"The quick brown fox jumps over the lazy dog.\nhello, world"

The following characters must be escaped:

  • \u{0}to \u{1f} (inclusive)
  • \n (newline)
  • \r (carriage return)
  • \t (tab) (optional)
  • "
  • ' (optional)
  • \
  • / (optional)
  • \u{8}
  • \u{c}
§

Array(Vec<Value>)

An array of JSON Values.

[
    "hello, world",
    1234,
    3.14,
    true,
    false,
    null,
]
§

Object(ValueMap)

A Mapping of JSON Values by their name.

{
    "tag": null,
    "registered": true,
    "age": 197,
    "name": "Fred",
    "classes": [
        "Algebra",
        "History of Programming",
        "Algorithms and Datastructures",
        "Cryptography",
    ],
    "rgb_for_some_reason": {
        "r": 4,
        "g": 7
        "b": 3,
    }
}

Implementations§

Source§

impl Value

Source

pub fn pretty_print_format( &self, indent: Indent, spacing: bool, ) -> PrettyPrint<'_>

Returns an object suitable for pretty printing.

§Arguments:
  • indent: Controls the indentation. Use Indent::Spaces(0) if you don’t want indentation (This defeats the purpose of pretty printing).
  • spacing: Determines whether or not there are spaces before and after colons.
Source

pub fn pretty_print(&self) -> PrettyPrint<'_>

Returns the default pretty printer.

Source§

impl Value

Source

pub fn push<T: Into<Value>>(&mut self, value: T)

Push value into a Value::Array. If the Value is Value::Null, convert it into a Value::Array and push value into it.

Panics if self Value is not Value::Null or Value::Array.

Source

pub fn insert<T: Into<Value>, K: InsertKey>( &mut self, k: K, v: T, ) -> Option<Value>

Insert value into a Value::Object. If the Value is Value::Null, convert it into a Value::Array and insert value into it.

Panics if self Value is not Value::Null or Value::Array.

Source

pub fn get<I: IndexOrKey>(&self, i_k: I) -> Option<&Value>

Get an immutable reference to a Value by index or key.

Source

pub fn get_mut<I: IndexOrKey>(&mut self, i_k: I) -> Option<&mut Value>

Get a mutable reference to a Value by index or key.

Source

pub fn len(&self) -> usize

Get the length of the Value if it is one of the following variants:

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Value

Source§

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

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

impl Display for Value

Source§

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

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

impl From<&str> for Value

Source§

fn from(value: &str) -> Self

Create a Value from string.

Source§

impl From<HashMap<String, Value>> for Value

Source§

fn from(value: ValueMap) -> Self

Create a Value from a ValueMap. (hashbrown::HashMap when not preserve_order, indexmap::IndexMap when preserve_order)

Source§

impl From<String> for Value

Source§

fn from(value: String) -> Self

Create a Value from a String.

Source§

impl From<Vec<Value>> for Value

Source§

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

Create a Value from a Vec

Source§

impl From<bool> for Value

Source§

fn from(value: bool) -> Self

Create a Value from a bool.

Source§

impl From<f64> for Value

Source§

fn from(value: f64) -> Self

Create a Value from an f64.

Source§

impl From<i64> for Value

Source§

fn from(value: i64) -> Self

Create a Value from an i64. Note that there is loss in precision because this value will be converted to f64.

Source§

impl FromStr for Value

Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parse a JSON Value from a string.

Source§

type Err = ParseError

The associated error which can be returned from parsing.
Source§

impl<I: IndexOrKey> Index<I> for Value

Source§

type Output = Value

The returned type after indexing.
Source§

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

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

impl<I: IndexOrKey> IndexMut<I> for Value

Source§

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

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

Auto Trait Implementations§

§

impl Freeze for Value

§

impl RefUnwindSafe for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnwindSafe for Value

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.