Skip to main content

Compound

Struct Compound 

Source
pub struct Compound<O: ByteOrder = BigEndian> { /* private fields */ }
Expand description

An owned, flat-buffer NBT compound map (TAG_Compound).

Implementations§

Source§

impl<O: ByteOrder> Compound<O>

Source

pub const fn new() -> Self

Creates an empty compound without heap allocation.

Source

pub fn as_ref(&self) -> CompoundRef<'_, Owned<O>>

Returns a lightweight Copy read-only view of this compound.

Source

pub fn is_empty(&self) -> bool

Returns true if this compound contains no entries.

Source

pub fn contains_key(&self, key: impl AsKey) -> bool

Returns true if key exists in this compound.

Source

pub fn at(&self, key: impl AsKey) -> ValueRef<'_, Owned<O>>

Looks up key for fallible chain navigation, returning ValueRef::End if missing.

Source

pub fn get(&self, key: impl AsKey) -> Option<ValueRef<'_, Owned<O>>>

Looks up key and returns its ValueRef if present.

Source

pub fn get_as<T: ?Sized + Tag>( &self, key: impl AsKey, ) -> Option<T::Ref<'_, Owned<O>>>

Looks up key and downcasts it to Rust tag type T (i32, str, [i8], Compound, TypedList<T>, etc.).

Source

pub fn get_bool(&self, key: impl AsKey) -> Option<bool>

Looks up key and returns it if its tag matches (get_bool).

Source

pub fn get_byte(&self, key: impl AsKey) -> Option<i8>

Looks up key and returns it if its tag matches (get_byte).

Source

pub fn get_short(&self, key: impl AsKey) -> Option<i16>

Looks up key and returns it if its tag matches (get_short).

Source

pub fn get_int(&self, key: impl AsKey) -> Option<i32>

Looks up key and returns it if its tag matches (get_int).

Source

pub fn get_long(&self, key: impl AsKey) -> Option<i64>

Looks up key and returns it if its tag matches (get_long).

Source

pub fn get_float(&self, key: impl AsKey) -> Option<f32>

Looks up key and returns it if its tag matches (get_float).

Source

pub fn get_double(&self, key: impl AsKey) -> Option<f64>

Looks up key and returns it if its tag matches (get_double).

Source

pub fn get_byte_array(&self, key: impl AsKey) -> Option<&[i8]>

Looks up key as a TAG_Byte_Array (&[i8]).

Source

pub fn get_string(&self, key: impl AsKey) -> Option<&MUTF8Str>

Looks up key as a zero-copy TAG_String (&MUTF8Str).

Source

pub fn get_str(&self, key: impl AsKey) -> Option<Cow<'_, str>>

Looks up key as a TAG_String and decodes it to UTF-8 (Cow<str>).

Source

pub fn get_list(&self, key: impl AsKey) -> Option<ListRef<'_, Owned<O>>>

Looks up key as a TAG_List (ListRef).

Source

pub fn get_compound(&self, key: impl AsKey) -> Option<CompoundRef<'_, Owned<O>>>

Looks up key as a TAG_Compound (CompoundRef).

Source

pub fn get_int_array(&self, key: impl AsKey) -> Option<&[I32<O>]>

Looks up key as a TAG_Int_Array (&[I32<O>]).

Source

pub fn get_long_array(&self, key: impl AsKey) -> Option<&[I64<O>]>

Looks up key as a TAG_Long_Array (&[I64<O>]).

Source

pub fn get_mut(&mut self, key: impl AsKey) -> Option<ValueMut<'_, O>>

Mutably borrows the entry at key as a ValueMut if present.

Source

pub fn get_mut_as<T: ?Sized + Tag>( &mut self, key: impl AsKey, ) -> Option<T::Mut<'_, O>>

Mutably borrows and downcasts the entry at key to Rust tag type T.

Source

pub fn get_byte_mut(&mut self, key: impl AsKey) -> Option<&mut i8>

Mutably borrows the entry at key if its tag matches i8.

Source

pub fn get_short_mut(&mut self, key: impl AsKey) -> Option<ScalarMut<'_, i16>>

Mutably borrows the entry at key if its tag matches i16.

Source

pub fn get_int_mut(&mut self, key: impl AsKey) -> Option<ScalarMut<'_, i32>>

Mutably borrows the entry at key if its tag matches i32.

Source

pub fn get_long_mut(&mut self, key: impl AsKey) -> Option<ScalarMut<'_, i64>>

Mutably borrows the entry at key if its tag matches i64.

Source

pub fn get_float_mut(&mut self, key: impl AsKey) -> Option<ScalarMut<'_, f32>>

Mutably borrows the entry at key if its tag matches f32.

Source

pub fn get_double_mut(&mut self, key: impl AsKey) -> Option<ScalarMut<'_, f64>>

Mutably borrows the entry at key if its tag matches f64.

Source

pub fn get_byte_array_mut( &mut self, key: impl AsKey, ) -> Option<Mut<'_, Vec<i8>>>

Mutably borrows the entry at key if its tag matches [i8].

Source

pub fn get_string_mut( &mut self, key: impl AsKey, ) -> Option<Mut<'_, MUTF8String>>

Mutably borrows the entry at key if its tag matches str.

Source

pub fn get_list_mut(&mut self, key: impl AsKey) -> Option<Mut<'_, List<O>>>

Mutably borrows the entry at key if its tag matches List<O>.

Source

pub fn get_compound_mut( &mut self, key: impl AsKey, ) -> Option<Mut<'_, Compound<O>>>

Mutably borrows the entry at key if its tag matches Compound<O>.

Source

pub fn get_int_array_mut( &mut self, key: impl AsKey, ) -> Option<Mut<'_, Vec<I32<O>>>>

Mutably borrows the entry at key if its tag matches [i32].

Source

pub fn get_long_array_mut( &mut self, key: impl AsKey, ) -> Option<Mut<'_, Vec<I64<O>>>>

Mutably borrows the entry at key if its tag matches [i64].

Source

pub fn insert<V: IntoNBT<O>>( &mut self, key: impl AsKey, value: V, ) -> Option<Value<O>>

Inserts or replaces an entry, returning the previous Value if key already existed.

§Panics

Panics if V::Tag is () (TagID::End), if the MUTF-8 encoded key exceeds u16::MAX bytes, or if a string value is longer than MUTF8String::MAX_LEN bytes once MUTF-8 encoded (see IntoNBT).

Source

pub fn insert_value( &mut self, key: impl AsKey, value: Value<O>, ) -> Option<Value<O>>

Inserts or replaces a dynamically typed Value, returning the previous value if key existed.

§Panics

Panics if value is Value::End or if the MUTF-8 encoded key exceeds u16::MAX bytes.

Source

pub fn remove(&mut self, key: impl AsKey) -> Option<Value<O>>

Removes and returns the entry at key, or None if absent.

Source

pub fn remove_as<T: ?Sized + Tag>( &mut self, key: impl AsKey, ) -> Option<T::Own<O>>

Removes and returns an entry only if its tag matches T (including crate::TypedList<E>); leaves the compound unchanged and returns None otherwise.

Source

pub fn clear(&mut self)

Removes all entries from this compound, retaining the underlying buffer capacity.

Source

pub fn iter(&self) -> CompoundIter<'_, Owned<O>> ⓘ

Returns an immutable iterator over (&MUTF8Str, ValueRef) entries.

Source

pub fn iter_mut(&mut self) -> CompoundIterMut<'_, O> ⓘ

Returns a mutable iterator over (&MUTF8Str, ValueMut) entries.

Source

pub fn write_to_vec<TARGET: ByteOrder>(&self) -> Vec<u8> ⓘ

Serializes this NBT value with an empty root name ("") into a Vec<u8>.

Source

pub fn write_to_vec_be(&self) -> Vec<u8> ⓘ

Serializes this NBT value in big-endian format with an empty root name ("").

Source

pub fn write_to_vec_le(&self) -> Vec<u8> ⓘ

Serializes this NBT value in little-endian format with an empty root name ("").

Source

pub fn write_into<TARGET: ByteOrder>(&self, out: &mut Vec<u8>)

Appends this NBT value with an empty root name ("") into out.

Source

pub fn write_into_be(&self, out: &mut Vec<u8>)

Appends this NBT value in big-endian format with an empty root name ("") into out.

Source

pub fn write_into_le(&self, out: &mut Vec<u8>)

Appends this NBT value in little-endian format with an empty root name ("") into out.

Source

pub fn write_nameless_to_vec<TARGET: ByteOrder>(&self) -> Vec<u8> ⓘ

Serializes this NBT value without a root name (Minecraft 1.20.2+ network format).

Source

pub fn write_nameless_to_vec_be(&self) -> Vec<u8> ⓘ

Serializes this NBT value in big-endian nameless format ([tag_id][payload]).

Source

pub fn write_nameless_to_vec_le(&self) -> Vec<u8> ⓘ

Serializes this NBT value in little-endian nameless format ([tag_id][payload]).

Source

pub fn write_nameless_into<TARGET: ByteOrder>(&self, out: &mut Vec<u8>)

Appends this NBT value without a root name into out.

Source

pub fn write_to<TARGET: ByteOrder>(&self, writer: impl Write) -> Result<()>

Writes this NBT value with an empty root name ("") to writer.

Source

pub fn write_to_be(&self, writer: impl Write) -> Result<()>

Writes this NBT value in big-endian format with an empty root name ("") to writer.

Source

pub fn write_to_le(&self, writer: impl Write) -> Result<()>

Writes this NBT value in little-endian format with an empty root name ("") to writer.

Source

pub fn write_named_to_vec<TARGET: ByteOrder>(&self, name: impl AsKey) -> Vec<u8> ⓘ

Serializes this NBT value with the given root name into a Vec<u8>.

Source

pub fn write_named_to_vec_be(&self, name: impl AsKey) -> Vec<u8> ⓘ

Serializes this NBT value in big-endian format with the given root name.

Source

pub fn write_named_to_vec_le(&self, name: impl AsKey) -> Vec<u8> ⓘ

Serializes this NBT value in little-endian format with the given root name.

Source

pub fn write_named_into<TARGET: ByteOrder>( &self, name: impl AsKey, out: &mut Vec<u8>, )

Appends this NBT value with the given root name into out.

Source

pub fn write_named_to<TARGET: ByteOrder>( &self, name: impl AsKey, writer: impl Write, ) -> Result<()>

Writes this NBT value with the given root name to writer.

Source

pub fn write_nameless_to<TARGET: ByteOrder>( &self, writer: impl Write, ) -> Result<()>

Writes this NBT value without a root name to writer.

Trait Implementations§

Source§

impl<'a, O: ByteOrder> AsCompoundRef<'a> for &'a Compound<O>

Source§

type Source = Owned<O>

Underlying Source (Borrowed<O> or Owned<O>).
Source§

fn as_compound_ref(self) -> CompoundRef<'a, Owned<O>>

Returns a lightweight Copy CompoundRef view.
Source§

impl<'a, O: ByteOrder> AsValueRef<'a> for &'a Compound<O>

Source§

type Source = Owned<O>

Underlying Source (Borrowed<O> or Owned<O>).
Source§

fn as_value_ref(self) -> ValueRef<'a, Owned<O>>

Returns a lightweight Copy ValueRef view.
Source§

impl<O: ByteOrder> Clone for Compound<O>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<O: ByteOrder> Debug for Compound<O>

Source§

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

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

impl<O: ByteOrder> Default for Compound<O>

Source§

fn default() -> Self

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

impl<'de, O: ByteOrder> Deserialize<'de> for Compound<O>

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<O: ByteOrder> Drop for Compound<O>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<AnyO: ByteOrder> ElementTag for Compound<AnyO>

Source§

impl<K: AsKey, V: IntoNBT<O>, O: ByteOrder> Extend<(K, V)> for Compound<O>

Source§

fn extend<I: IntoIterator<Item = (K, V)>>(&mut self, iter: I)

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

fn extend_one(&mut self, item: T)

🔬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, O: ByteOrder> From<&'a mut Compound<O>> for ValueMut<'a, O>

Source§

fn from(value: &'a mut Compound<O>) -> Self

Converts to this type from the input type.
Source§

impl<O: ByteOrder> From<Compound<O>> for Value<O>

Source§

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

Converts to this type from the input type.
Source§

impl<K: AsKey, V: IntoNBT<O>, O: ByteOrder> FromIterator<(K, V)> for Compound<O>

Source§

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

Creates a value from an iterator. Read more
Source§

impl<'a, O: ByteOrder> IntoIterator for &'a Compound<O>

Source§

type Item = (&'a MUTF8Str, ValueRef<'a, Owned<O>>)

The type of the elements being iterated over.
Source§

type IntoIter = CompoundIter<'a, Owned<O>>

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, O: ByteOrder> IntoIterator for &'a mut Compound<O>

Source§

type Item = (&'a MUTF8Str, ValueMut<'a, O>)

The type of the elements being iterated over.
Source§

type IntoIter = CompoundIterMut<'a, O>

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<O: ByteOrder> IntoNBT<O> for Compound<O>

Source§

type Tag = Compound

Canonical ElementTag (i32, str, [i8], Compound, List, etc.) produced by self.
Source§

fn into_nbt(self) -> Self

Converts self into its owned NBT storage payload for byte order O.
Source§

impl<O: ByteOrder> PartialEq for Compound<O>

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<O: ByteOrder, S: Source> PartialEq<CompoundRef<'_, S>> for Compound<O>

Source§

fn eq(&self, other: &CompoundRef<'_, S>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<O: ByteOrder> Serialize for Compound<O>

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl<O: ByteOrder> SlotValue for Compound<O>

Source§

impl<AnyO: ByteOrder> Tag for Compound<AnyO>

Source§

const TAG_ID: TagID = TagID::Compound

Wire TagID corresponding to this Rust type.
Source§

type Ref<'a, S: Source> = CompoundRef<'a, S>

Read-only view type returned by get_as::<T>.
Source§

type Mut<'a, O: ByteOrder> = Mut<'a, Compound<O>>

Mutable guard/reference type returned by get_mut_as::<T>.
Source§

type Own<O: ByteOrder> = Compound<O>

Owned value type returned by remove_as::<T> / into_::<T>.

Auto Trait Implementations§

§

impl<O> Forget for Compound<O>

§

impl<O> Freeze for Compound<O>
where PhantomData<fn() -> O>: Freeze,

§

impl<O> Move for Compound<O>

§

impl<O> RefUnwindSafe for Compound<O>
where PhantomData<fn() -> O>: RefUnwindSafe,

§

impl<O> Send for Compound<O>
where PhantomData<fn() -> O>: Send,

§

impl<O> Sync for Compound<O>
where PhantomData<fn() -> O>: Sync,

§

impl<O> Unpin for Compound<O>
where PhantomData<fn() -> O>: Unpin,

§

impl<O> UnsafeUnpin for Compound<O>
where PhantomData<fn() -> O>: UnsafeUnpin,

§

impl<O> UnwindSafe for Compound<O>
where PhantomData<fn() -> O>: UnwindSafe,

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.