jzon::object

Struct Object

Source
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() -> Self

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) -> Self

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) -> Self

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

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: AsRef<str>, V: Into<JsonValue>> FromIterator<(K, V)> for Object

Source§

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

Creates a value from an iterator. Read more
Source§

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

Source§

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");
}
Source§

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

Source§

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 IntoIterator for Object

Source§

type Item = (String, JsonValue)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq<JsonValue> for Object

Source§

fn eq(&self, other: &JsonValue) -> 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<'a> PartialEq<Object> for &'a JsonValue

Source§

fn eq(&self, other: &Object) -> 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 PartialEq<Object> for JsonValue

Source§

fn eq(&self, other: &Object) -> 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 PartialEq for Object

Source§

fn eq(&self, other: &Object) -> 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.

Auto Trait Implementations§

§

impl Freeze for Object

§

impl RefUnwindSafe for Object

§

impl Send for Object

§

impl Sync for Object

§

impl Unpin for Object

§

impl UnwindSafe for Object

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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, 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.