[−][src]Struct json::object::Object
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.
Methods
impl Object
[src]
impl Object
pub fn new() -> Self
[src]
pub fn new() -> Self
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]
pub fn with_capacity(capacity: usize) -> Self
Create a new Object
with memory preallocated for capacity
number
of entries.
pub fn insert(&mut self, key: &str, value: JsonValue)
[src]
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.
pub fn override_last(&mut self, value: JsonValue)
[src]
pub fn override_last(&mut self, value: JsonValue)
: Was only meant for internal use
pub fn get(&self, key: &str) -> Option<&JsonValue>
[src]
pub fn get(&self, key: &str) -> Option<&JsonValue>
pub fn get_mut(&mut self, key: &str) -> Option<&mut JsonValue>
[src]
pub fn get_mut(&mut self, key: &str) -> Option<&mut JsonValue>
pub fn remove(&mut self, key: &str) -> Option<JsonValue>
[src]
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
.
pub fn len(&self) -> usize
[src]
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
[src]
pub fn is_empty(&self) -> bool
pub fn clear(&mut self)
[src]
pub fn clear(&mut self)
Wipe the Object
clear. The capacity will remain untouched.
ⓘImportant traits for Iter<'a>pub fn iter(&self) -> Iter
[src]
pub fn iter(&self) -> Iter
ⓘImportant traits for IterMut<'a>pub fn iter_mut(&mut self) -> IterMut
[src]
pub fn iter_mut(&mut self) -> IterMut
pub fn dump(&self) -> String
[src]
pub fn dump(&self) -> String
Prints out the value as JSON string.
pub fn pretty(&self, spaces: u16) -> String
[src]
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
impl Clone for Object
[src]
impl Clone for Object
fn clone(&self) -> Self
[src]
fn clone(&self) -> Self
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl From<Object> for JsonValue
[src]
impl From<Object> for JsonValue
impl PartialEq<Object> for JsonValue
[src]
impl PartialEq<Object> for JsonValue
fn eq(&self, other: &Object) -> bool
[src]
fn eq(&self, other: &Object) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl<'a> PartialEq<Object> for &'a JsonValue
[src]
impl<'a> PartialEq<Object> for &'a JsonValue
fn eq(&self, other: &Object) -> bool
[src]
fn eq(&self, other: &Object) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl PartialEq<JsonValue> for Object
[src]
impl PartialEq<JsonValue> for Object
fn eq(&self, other: &JsonValue) -> bool
[src]
fn eq(&self, other: &JsonValue) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl PartialEq<Object> for Object
[src]
impl PartialEq<Object> for Object
fn eq(&self, other: &Object) -> bool
[src]
fn eq(&self, other: &Object) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl Debug for Object
[src]
impl Debug for Object
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<'a> Index<&'a str> for Object
[src]
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.
fn index(&self, index: &str) -> &JsonValue
[src]
fn index(&self, index: &str) -> &JsonValue
Performs the indexing (container[index]
) operation.
impl Index<String> for Object
[src]
impl Index<String> for Object
type Output = JsonValue
The returned type after indexing.
fn index(&self, index: String) -> &JsonValue
[src]
fn index(&self, index: String) -> &JsonValue
Performs the indexing (container[index]
) operation.
impl<'a> Index<&'a String> for Object
[src]
impl<'a> Index<&'a String> for Object
type Output = JsonValue
The returned type after indexing.
fn index(&self, index: &String) -> &JsonValue
[src]
fn index(&self, index: &String) -> &JsonValue
Performs the indexing (container[index]
) operation.
impl<'a> IndexMut<&'a str> for Object
[src]
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); }
fn index_mut(&mut self, index: &str) -> &mut JsonValue
[src]
fn index_mut(&mut self, index: &str) -> &mut JsonValue
Performs the mutable indexing (container[index]
) operation.
impl IndexMut<String> for Object
[src]
impl IndexMut<String> for Object
fn index_mut(&mut self, index: String) -> &mut JsonValue
[src]
fn index_mut(&mut self, index: String) -> &mut JsonValue
Performs the mutable indexing (container[index]
) operation.
impl<'a> IndexMut<&'a String> for Object
[src]
impl<'a> IndexMut<&'a String> for Object
Auto Trait Implementations
Blanket Implementations
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
type Owned = T
fn to_owned(&self) -> T
[src]
fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
fn clone_into(&self, target: &mut T)
[src]
fn clone_into(&self, target: &mut T)
🔬 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 for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
try_from
)Performs the conversion.
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
try_from
)Performs the conversion.
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId
[src]
fn get_type_id(&self) -> TypeId
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Gets the TypeId
of self
. Read more