# Struct json::object::Object [−] [src]

    pub struct Object { /* fields omitted */ }

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

### `impl Object` [src]

#### `pub fn new() -> Self` [src]

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

#### `pub fn with_capacity(capacity: usize) -> Self` [src]

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

#### `pub fn insert(&mut self, key: &str, value: JsonValue)` [src]

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.

#### `pub fn override_last(&mut self, value: JsonValue)` [src]

👎 Deprecated since 0.11.11:

Was only meant for internal use

#### `pub fn get(&self, key: &str) -> Option<&JsonValue>` [src]

#### `pub fn get_mut(&mut self, key: &str) -> Option<&mut JsonValue>` [src]

#### `pub fn remove(&mut self, key: &str) -> Option<JsonValue>` [src]

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

#### `pub fn len(&self) -> usize` [src]

#### `pub fn is_empty(&self) -> bool` [src]

#### `pub fn clear(&mut self)` [src]

Wipe the `Object` clear. The capacity will remain untouched.

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

### Notable traits for Iter<'a>

`impl<'a> Iterator for Iter<'a> type Item = (&'a str, &'a JsonValue);`
` [src]

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

### Notable traits for IterMut<'a>

`impl<'a> Iterator for IterMut<'a> type Item = (&'a str, &'a mut JsonValue);`
` [src]

#### `pub fn dump(&self) -> String` [src]

Prints out the value as JSON string.

#### `pub fn pretty(&self, spaces: u16) -> String` [src]

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

## Trait Implementations

### `impl Clone for Object` [src]

#### `fn clone(&self) -> Self` [src]

Returns a copy of the value. Read more

#### `pub fn clone_from(&mut self, source: &Self)`1.0.0 [src]

Performs copy-assignment from `source`. Read more

### `impl Debug for Object` [src]

#### `fn fmt(&self, f: &mut Formatter<'_>) -> Result` [src]

Formats the value using the given formatter. Read more

### `impl From<Object> for JsonValue` [src]

#### `fn from(val: Object) -> JsonValue` [src]

Performs the conversion.

### `impl<K: AsRef<str>, V: Into<JsonValue>> FromIterator<(K, V)> for Object` [src]

#### `fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> Self` [src]

Creates a value from an iterator. Read more

### `impl<'a> Index<&'a String> for Object` [src]

#### `type Output = JsonValue`

The returned type after indexing.

#### `fn index(&self, index: &String) -> &JsonValue` [src]

Performs the indexing (`container[index]`) operation.

### `impl<'a> Index<&'a str> for Object` [src]

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.

#### `fn index(&self, index: &str) -> &JsonValue` [src]

Performs the indexing (`container[index]`) operation.

### `impl Index<String> for Object` [src]

#### `type Output = JsonValue`

The returned type after indexing.

#### `fn index(&self, index: String) -> &JsonValue` [src]

Performs the indexing (`container[index]`) operation.

### `impl<'a> IndexMut<&'a String> for Object` [src]

#### `fn index_mut(&mut self, index: &String) -> &mut JsonValue` [src]

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

### `impl<'a> IndexMut<&'a str> for Object` [src]

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);
    }

#### `fn index_mut(&mut self, index: &str) -> &mut JsonValue` [src]

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

### `impl IndexMut<String> for Object` [src]

#### `fn index_mut(&mut self, index: String) -> &mut JsonValue` [src]

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

### `impl PartialEq<JsonValue> for Object` [src]

#### `fn eq(&self, other: &JsonValue) -> bool` [src]

This method tests for `self` and `other` values to be equal, and is used by `==`. Read more

#### `#[must_use]pub fn ne(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests for `!=`.

### `impl PartialEq<Object> for JsonValue` [src]

#### `fn eq(&self, other: &Object) -> bool` [src]

This method tests for `self` and `other` values to be equal, and is used by `==`. Read more

#### `#[must_use]pub fn ne(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests for `!=`.

### `impl<'a> PartialEq<Object> for &'a JsonValue` [src]

#### `fn eq(&self, other: &Object) -> bool` [src]

This method tests for `self` and `other` values to be equal, and is used by `==`. Read more

#### `#[must_use]pub fn ne(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests for `!=`.

### `impl PartialEq<Object> for Object` [src]

#### `fn eq(&self, other: &Object) -> bool` [src]

This method tests for `self` and `other` values to be equal, and is used by `==`. Read more

#### `#[must_use]pub fn ne(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests for `!=`.

## Auto Trait Implementations

### `impl RefUnwindSafe for Object`

### `impl Send for Object`

### `impl Sync for Object`

### `impl Unpin for Object`

### `impl UnwindSafe for Object`

## Blanket Implementations

### `impl<T> Any for T where
T: 'static + ?Sized,` [src]

#### `pub fn type_id(&self) -> TypeId` [src]

Gets the `TypeId` of `self`. Read more

### `impl<T> Borrow<T> for T where
T: ?Sized,` [src]

#### `pub fn borrow(&self) -> &T` [src]

Immutably borrows from an owned value. Read more

### `impl<T> BorrowMut<T> for T where
T: ?Sized,` [src]

#### `pub fn borrow_mut(&mut self) -> &mut T` [src]

Mutably borrows from an owned value. Read more

### `impl<T> From<T> for T` [src]

#### `pub fn from(t: T) -> T` [src]

Performs the conversion.

### `impl<T, U> Into<U> for T where
U: From<T>,` [src]

#### `pub fn into(self) -> U` [src]

Performs the conversion.

### `impl<T> ToOwned for T where
T: Clone,` [src]

#### `type Owned = T`

The resulting type after obtaining ownership.

#### `pub fn to_owned(&self) -> T` [src]

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

#### `pub fn clone_into(&self, target: &mut T)` [src]

🔬 This is a nightly-only experimental API. (`toowned_clone_into`)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

### `impl<T, U> TryFrom<U> for T where
U: Into<T>,` [src]

#### `type Error = Infallible`

The type returned in the event of a conversion error.

#### `pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>` [src]

Performs the conversion.

### `impl<T, U> TryInto<U> for T where
U: TryFrom<T>,` [src]

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

The type returned in the event of a conversion error.

#### `pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>` [src]

Performs the conversion.