pub struct Compound<S = String> { /* private fields */ }
Expand description

A map type with String keys and Value values.

Implementations§

source§

impl<S> Compound<S>

source

pub fn new() -> Self

source

pub fn with_capacity(cap: usize) -> Self

source

pub fn clear(&mut self)

source§

impl<S> Compound<S>
where S: Ord + Hash,

source

pub fn get<Q>(&self, k: &Q) -> Option<&Value<S>>
where Q: ?Sized + AsBorrowed<S>, <Q as AsBorrowed<S>>::Borrowed: Hash + Ord, S: Borrow<<Q as AsBorrowed<S>>::Borrowed>,

source

pub fn contains_key<Q>(&self, k: &Q) -> bool
where Q: ?Sized + AsBorrowed<S>, <Q as AsBorrowed<S>>::Borrowed: Hash + Ord, S: Borrow<<Q as AsBorrowed<S>>::Borrowed>,

source

pub fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut Value<S>>
where Q: ?Sized + AsBorrowed<S>, <Q as AsBorrowed<S>>::Borrowed: Hash + Ord, S: Borrow<<Q as AsBorrowed<S>>::Borrowed>,

source

pub fn get_key_value<Q>(&self, k: &Q) -> Option<(&S, &Value<S>)>
where Q: ?Sized + AsBorrowed<S>, <Q as AsBorrowed<S>>::Borrowed: Hash + Ord, S: Borrow<<Q as AsBorrowed<S>>::Borrowed>,

source

pub fn insert<K, V>(&mut self, k: K, v: V) -> Option<Value<S>>
where K: Into<S>, V: Into<Value<S>>,

source

pub fn remove<Q>(&mut self, k: &Q) -> Option<Value<S>>
where Q: ?Sized + AsBorrowed<S>, <Q as AsBorrowed<S>>::Borrowed: Hash + Ord, S: Borrow<<Q as AsBorrowed<S>>::Borrowed>,

source

pub fn remove_entry<Q>(&mut self, k: &Q) -> Option<(S, Value<S>)>
where S: Borrow<Q>, Q: ?Sized + Ord + Hash,

source

pub fn append(&mut self, other: &mut Self)

source

pub fn entry<K>(&mut self, k: K) -> Entry<'_, S>
where K: Into<S>,

source

pub fn len(&self) -> usize

source

pub fn is_empty(&self) -> bool

source

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

source

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

source

pub fn keys(&self) -> Keys<'_, S>

source

pub fn values(&self) -> Values<'_, S>

source

pub fn values_mut(&mut self) -> ValuesMut<'_, S>

source

pub fn retain<F>(&mut self, f: F)
where F: FnMut(&S, &mut Value<S>) -> bool,

source

pub fn merge(&mut self, other: Compound<S>)

Inserts all items from other into self recursively.

Example
use valence_nbt::compound;

let mut this = compound! {
    "foo" => 10,
    "bar" => compound! {
        "baz" => 20,
    }
};

let other = compound! {
    "foo" => 15,
    "bar" => compound! {
        "quux" => "hello",
    }
};

this.merge(other);

assert_eq!(
    this,
    compound! {
        "foo" => 15,
        "bar" => compound! {
            "baz" => 20,
            "quux" => "hello",
        }
    }
);

Trait Implementations§

source§

impl<S: Clone> Clone for Compound<S>

source§

fn clone(&self) -> Compound<S>

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<S: Debug> Debug for Compound<S>

source§

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

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

impl<S: Default> Default for Compound<S>

source§

fn default() -> Compound<S>

Returns the “default value” for a type. Read more
source§

impl<S> Extend<(S, Value<S>)> for Compound<S>
where S: Ord + Hash,

source§

fn extend<T>(&mut self, iter: T)
where T: IntoIterator<Item = (S, Value<S>)>,

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<'a, S> From<&'a Compound<S>> for ValueRef<'a, S>

source§

fn from(v: &'a Compound<S>) -> Self

Converts to this type from the input type.
source§

impl<'a, S> From<&'a mut Compound<S>> for ValueMut<'a, S>

source§

fn from(v: &'a mut Compound<S>) -> Self

Converts to this type from the input type.
source§

impl<S> From<Compound<S>> for Value<S>

source§

fn from(v: Compound<S>) -> Self

Converts to this type from the input type.
source§

impl<S> FromIterator<(S, Value<S>)> for Compound<S>
where S: Ord + Hash,

source§

fn from_iter<T>(iter: T) -> Self
where T: IntoIterator<Item = (S, Value<S>)>,

Creates a value from an iterator. Read more
source§

impl<S, Q> Index<&Q> for Compound<S>
where S: Borrow<Q> + Ord + Hash, Q: ?Sized + Ord + Hash,

§

type Output = Value<S>

The returned type after indexing.
source§

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

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

impl<S, Q> IndexMut<&Q> for Compound<S>
where S: Borrow<Q> + Hash + Ord, Q: ?Sized + Ord + Hash,

source§

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

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

impl<'a, S> IntoIterator for &'a Compound<S>

§

type Item = (&'a S, &'a Value<S>)

The type of the elements being iterated over.
§

type IntoIter = Iter<'a, S>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'a, S> IntoIterator for &'a mut Compound<S>

§

type Item = (&'a S, &'a mut Value<S>)

The type of the elements being iterated over.
§

type IntoIter = IterMut<'a, S>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<S> IntoIterator for Compound<S>

§

type Item = (S, Value<S>)

The type of the elements being iterated over.
§

type IntoIter = IntoIter<S>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<S> PartialEq for Compound<S>
where S: Ord + Hash,

source§

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

§

impl<S> RefUnwindSafe for Compound<S>
where S: RefUnwindSafe,

§

impl<S> Send for Compound<S>
where S: Send,

§

impl<S> Sync for Compound<S>
where S: Sync,

§

impl<S> Unpin for Compound<S>

§

impl<S> UnwindSafe for Compound<S>
where S: RefUnwindSafe,

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> 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,

§

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>,

§

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>,

§

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.