pub struct Object { /* private fields */ }
Expand description

A binary tree implementation of a string -> JsonValue map. You normally don’t have to interact with instances of Object, much more likely you will be using the JsonValue::Object variant, which wraps around this struct.

Implementations§

source§

impl Object

source

pub fn new() -> Object

Create a new, empty instance of Object. Empty Object performs no allocation until a value is inserted into it.

source

pub fn with_capacity(capacity: usize) -> Object

Create a new Object with memory preallocated for capacity number of entries.

source

pub fn insert(&mut self, key: &str, value: JsonValue)

Insert a new entry, or override an existing one. Note that key has to be a &str slice and not an owned String. The internals of Object will handle the heap allocation of the key if needed for better performance.

source

pub fn override_last(&mut self, value: JsonValue)

👎Deprecated since 0.11.11: Was only meant for internal use
source

pub fn get(&self, key: &str) -> Option<&JsonValue>

source

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

source

pub fn remove(&mut self, key: &str) -> Option<JsonValue>

Attempts to remove the value behind key, if successful will return the JsonValue stored behind the key.

source

pub fn len(&self) -> usize

source

pub fn is_empty(&self) -> bool

source

pub fn clear(&mut self)

Wipe the Object clear. The capacity will remain untouched.

source

pub fn iter(&self) -> Iter<'_>

source

pub fn iter_mut(&mut self) -> IterMut<'_>

source

pub fn dump(&self) -> String

Prints out the value as JSON string.

source

pub fn pretty(&self, spaces: u16) -> String

Pretty prints out the value as JSON string. Takes an argument that’s number of spaces to indent new blocks with.

Trait Implementations§

source§

impl Clone for Object

source§

fn clone(&self) -> Object

Returns a copy 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 Object

source§

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

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

impl From<Object> for JsonValue

source§

fn from(val: Object) -> JsonValue

Converts to this type from the input type.
source§

impl<K, V> FromIterator<(K, V)> for Objectwhere K: AsRef<str>, V: Into<JsonValue>,

source§

fn from_iter<I>(iter: I) -> Objectwhere I: IntoIterator<Item = (K, V)>,

Creates a value from an iterator. Read more
source§

impl<'a> Index<&'a String> for Object

§

type Output = JsonValue

The returned type after indexing.
source§

fn index(&self, index: &String) -> &JsonValue

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

impl<'a> Index<&'a str> for Object

Implements indexing by &str to easily access object members:

Example
let value = object!{
    foo: "bar"
};

if let JsonValue::Object(object) = value {
  assert!(object["foo"] == "bar");
}
§

type Output = JsonValue

The returned type after indexing.
source§

fn index(&self, index: &str) -> &JsonValue

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

impl Index<String> for Object

§

type Output = JsonValue

The returned type after indexing.
source§

fn index(&self, index: String) -> &JsonValue

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

impl<'a> IndexMut<&'a String> for Object

source§

fn index_mut(&mut self, index: &String) -> &mut JsonValue

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

impl<'a> IndexMut<&'a str> for Object

Implements mutable indexing by &str to easily modify object members:

Example
let value = object!{};

if let JsonValue::Object(mut object) = value {
  object["foo"] = 42.into();

  assert!(object["foo"] == 42);
}
source§

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

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

impl IndexMut<String> for Object

source§

fn index_mut(&mut self, index: String) -> &mut JsonValue

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

impl PartialEq<JsonValue> for Object

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> PartialEq<Object> for &'a JsonValue

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Object> for JsonValue

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Object> for Object

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

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, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V