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>
impl<O: ByteOrder> Compound<O>
Sourcepub fn as_ref(&self) -> CompoundRef<'_, Owned<O>>
pub fn as_ref(&self) -> CompoundRef<'_, Owned<O>>
Returns a lightweight Copy read-only view of this compound.
Sourcepub fn contains_key(&self, key: impl AsKey) -> bool
pub fn contains_key(&self, key: impl AsKey) -> bool
Returns true if key exists in this compound.
Sourcepub fn at(&self, key: impl AsKey) -> ValueRef<'_, Owned<O>>
pub fn at(&self, key: impl AsKey) -> ValueRef<'_, Owned<O>>
Looks up key for fallible chain navigation, returning ValueRef::End if missing.
Sourcepub fn get(&self, key: impl AsKey) -> Option<ValueRef<'_, Owned<O>>>
pub fn get(&self, key: impl AsKey) -> Option<ValueRef<'_, Owned<O>>>
Looks up key and returns its ValueRef if present.
Sourcepub fn get_as<T: ?Sized + Tag>(
&self,
key: impl AsKey,
) -> Option<T::Ref<'_, Owned<O>>>
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.).
Sourcepub fn get_bool(&self, key: impl AsKey) -> Option<bool>
pub fn get_bool(&self, key: impl AsKey) -> Option<bool>
Looks up key and returns it if its tag matches (get_bool).
Sourcepub fn get_byte(&self, key: impl AsKey) -> Option<i8>
pub fn get_byte(&self, key: impl AsKey) -> Option<i8>
Looks up key and returns it if its tag matches (get_byte).
Sourcepub fn get_short(&self, key: impl AsKey) -> Option<i16>
pub fn get_short(&self, key: impl AsKey) -> Option<i16>
Looks up key and returns it if its tag matches (get_short).
Sourcepub fn get_int(&self, key: impl AsKey) -> Option<i32>
pub fn get_int(&self, key: impl AsKey) -> Option<i32>
Looks up key and returns it if its tag matches (get_int).
Sourcepub fn get_long(&self, key: impl AsKey) -> Option<i64>
pub fn get_long(&self, key: impl AsKey) -> Option<i64>
Looks up key and returns it if its tag matches (get_long).
Sourcepub fn get_float(&self, key: impl AsKey) -> Option<f32>
pub fn get_float(&self, key: impl AsKey) -> Option<f32>
Looks up key and returns it if its tag matches (get_float).
Sourcepub fn get_double(&self, key: impl AsKey) -> Option<f64>
pub fn get_double(&self, key: impl AsKey) -> Option<f64>
Looks up key and returns it if its tag matches (get_double).
Sourcepub fn get_byte_array(&self, key: impl AsKey) -> Option<&[i8]>
pub fn get_byte_array(&self, key: impl AsKey) -> Option<&[i8]>
Looks up key as a TAG_Byte_Array (&[i8]).
Sourcepub fn get_string(&self, key: impl AsKey) -> Option<&MUTF8Str>
pub fn get_string(&self, key: impl AsKey) -> Option<&MUTF8Str>
Looks up key as a zero-copy TAG_String (&MUTF8Str).
Sourcepub fn get_str(&self, key: impl AsKey) -> Option<Cow<'_, str>>
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>).
Sourcepub fn get_list(&self, key: impl AsKey) -> Option<ListRef<'_, Owned<O>>>
pub fn get_list(&self, key: impl AsKey) -> Option<ListRef<'_, Owned<O>>>
Looks up key as a TAG_List (ListRef).
Sourcepub fn get_compound(&self, key: impl AsKey) -> Option<CompoundRef<'_, Owned<O>>>
pub fn get_compound(&self, key: impl AsKey) -> Option<CompoundRef<'_, Owned<O>>>
Looks up key as a TAG_Compound (CompoundRef).
Sourcepub fn get_int_array(&self, key: impl AsKey) -> Option<&[I32<O>]>
pub fn get_int_array(&self, key: impl AsKey) -> Option<&[I32<O>]>
Looks up key as a TAG_Int_Array (&[I32<O>]).
Sourcepub fn get_long_array(&self, key: impl AsKey) -> Option<&[I64<O>]>
pub fn get_long_array(&self, key: impl AsKey) -> Option<&[I64<O>]>
Looks up key as a TAG_Long_Array (&[I64<O>]).
Sourcepub fn get_mut(&mut self, key: impl AsKey) -> Option<ValueMut<'_, O>>
pub fn get_mut(&mut self, key: impl AsKey) -> Option<ValueMut<'_, O>>
Mutably borrows the entry at key as a ValueMut if present.
Sourcepub fn get_mut_as<T: ?Sized + Tag>(
&mut self,
key: impl AsKey,
) -> Option<T::Mut<'_, O>>
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.
Sourcepub fn get_byte_mut(&mut self, key: impl AsKey) -> Option<&mut i8>
pub fn get_byte_mut(&mut self, key: impl AsKey) -> Option<&mut i8>
Mutably borrows the entry at key if its tag matches i8.
Sourcepub fn get_short_mut(&mut self, key: impl AsKey) -> Option<ScalarMut<'_, i16>>
pub fn get_short_mut(&mut self, key: impl AsKey) -> Option<ScalarMut<'_, i16>>
Mutably borrows the entry at key if its tag matches i16.
Sourcepub fn get_int_mut(&mut self, key: impl AsKey) -> Option<ScalarMut<'_, i32>>
pub fn get_int_mut(&mut self, key: impl AsKey) -> Option<ScalarMut<'_, i32>>
Mutably borrows the entry at key if its tag matches i32.
Sourcepub fn get_long_mut(&mut self, key: impl AsKey) -> Option<ScalarMut<'_, i64>>
pub fn get_long_mut(&mut self, key: impl AsKey) -> Option<ScalarMut<'_, i64>>
Mutably borrows the entry at key if its tag matches i64.
Sourcepub fn get_float_mut(&mut self, key: impl AsKey) -> Option<ScalarMut<'_, f32>>
pub fn get_float_mut(&mut self, key: impl AsKey) -> Option<ScalarMut<'_, f32>>
Mutably borrows the entry at key if its tag matches f32.
Sourcepub fn get_double_mut(&mut self, key: impl AsKey) -> Option<ScalarMut<'_, f64>>
pub fn get_double_mut(&mut self, key: impl AsKey) -> Option<ScalarMut<'_, f64>>
Mutably borrows the entry at key if its tag matches f64.
Sourcepub fn get_byte_array_mut(
&mut self,
key: impl AsKey,
) -> Option<Mut<'_, Vec<i8>>>
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].
Sourcepub fn get_string_mut(
&mut self,
key: impl AsKey,
) -> Option<Mut<'_, MUTF8String>>
pub fn get_string_mut( &mut self, key: impl AsKey, ) -> Option<Mut<'_, MUTF8String>>
Mutably borrows the entry at key if its tag matches str.
Sourcepub fn get_list_mut(&mut self, key: impl AsKey) -> Option<Mut<'_, List<O>>>
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>.
Sourcepub fn get_compound_mut(
&mut self,
key: impl AsKey,
) -> Option<Mut<'_, Compound<O>>>
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>.
Sourcepub fn get_int_array_mut(
&mut self,
key: impl AsKey,
) -> Option<Mut<'_, Vec<I32<O>>>>
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].
Sourcepub fn get_long_array_mut(
&mut self,
key: impl AsKey,
) -> Option<Mut<'_, Vec<I64<O>>>>
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].
Sourcepub fn insert<V: IntoNBT<O>>(
&mut self,
key: impl AsKey,
value: V,
) -> Option<Value<O>>
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).
Sourcepub fn insert_value(
&mut self,
key: impl AsKey,
value: Value<O>,
) -> Option<Value<O>>
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.
Sourcepub fn remove(&mut self, key: impl AsKey) -> Option<Value<O>>
pub fn remove(&mut self, key: impl AsKey) -> Option<Value<O>>
Removes and returns the entry at key, or None if absent.
Sourcepub fn remove_as<T: ?Sized + Tag>(
&mut self,
key: impl AsKey,
) -> Option<T::Own<O>>
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.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Removes all entries from this compound, retaining the underlying buffer capacity.
Sourcepub fn iter(&self) -> CompoundIter<'_, Owned<O>> ⓘ
pub fn iter(&self) -> CompoundIter<'_, Owned<O>> ⓘ
Returns an immutable iterator over (&MUTF8Str, ValueRef) entries.
Sourcepub fn iter_mut(&mut self) -> CompoundIterMut<'_, O> ⓘ
pub fn iter_mut(&mut self) -> CompoundIterMut<'_, O> ⓘ
Returns a mutable iterator over (&MUTF8Str, ValueMut) entries.
Sourcepub fn write_to_vec<TARGET: ByteOrder>(&self) -> Vec<u8> ⓘ
pub fn write_to_vec<TARGET: ByteOrder>(&self) -> Vec<u8> ⓘ
Serializes this NBT value with an empty root name ("") into a Vec<u8>.
Sourcepub fn write_to_vec_be(&self) -> Vec<u8> ⓘ
pub fn write_to_vec_be(&self) -> Vec<u8> ⓘ
Serializes this NBT value in big-endian format with an empty root name ("").
Sourcepub fn write_to_vec_le(&self) -> Vec<u8> ⓘ
pub fn write_to_vec_le(&self) -> Vec<u8> ⓘ
Serializes this NBT value in little-endian format with an empty root name ("").
Sourcepub fn write_into<TARGET: ByteOrder>(&self, out: &mut Vec<u8>)
pub fn write_into<TARGET: ByteOrder>(&self, out: &mut Vec<u8>)
Appends this NBT value with an empty root name ("") into out.
Sourcepub fn write_into_be(&self, out: &mut Vec<u8>)
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.
Sourcepub fn write_into_le(&self, out: &mut Vec<u8>)
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.
Sourcepub fn write_nameless_to_vec<TARGET: ByteOrder>(&self) -> Vec<u8> ⓘ
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).
Sourcepub fn write_nameless_to_vec_be(&self) -> Vec<u8> ⓘ
pub fn write_nameless_to_vec_be(&self) -> Vec<u8> ⓘ
Serializes this NBT value in big-endian nameless format ([tag_id][payload]).
Sourcepub fn write_nameless_to_vec_le(&self) -> Vec<u8> ⓘ
pub fn write_nameless_to_vec_le(&self) -> Vec<u8> ⓘ
Serializes this NBT value in little-endian nameless format ([tag_id][payload]).
Sourcepub fn write_nameless_into<TARGET: ByteOrder>(&self, out: &mut Vec<u8>)
pub fn write_nameless_into<TARGET: ByteOrder>(&self, out: &mut Vec<u8>)
Appends this NBT value without a root name into out.
Sourcepub fn write_to<TARGET: ByteOrder>(&self, writer: impl Write) -> Result<()>
pub fn write_to<TARGET: ByteOrder>(&self, writer: impl Write) -> Result<()>
Writes this NBT value with an empty root name ("") to writer.
Sourcepub fn write_to_be(&self, writer: impl Write) -> Result<()>
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.
Sourcepub fn write_to_le(&self, writer: impl Write) -> Result<()>
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.
Sourcepub fn write_named_to_vec<TARGET: ByteOrder>(&self, name: impl AsKey) -> Vec<u8> ⓘ
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>.
Sourcepub fn write_named_to_vec_be(&self, name: impl AsKey) -> Vec<u8> ⓘ
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.
Sourcepub fn write_named_to_vec_le(&self, name: impl AsKey) -> Vec<u8> ⓘ
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.
Sourcepub fn write_named_into<TARGET: ByteOrder>(
&self,
name: impl AsKey,
out: &mut Vec<u8>,
)
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.
Trait Implementations§
Source§impl<'a, O: ByteOrder> AsCompoundRef<'a> for &'a Compound<O>
impl<'a, O: ByteOrder> AsCompoundRef<'a> for &'a Compound<O>
Source§fn as_compound_ref(self) -> CompoundRef<'a, Owned<O>>
fn as_compound_ref(self) -> CompoundRef<'a, Owned<O>>
Copy CompoundRef view.Source§impl<'a, O: ByteOrder> AsValueRef<'a> for &'a Compound<O>
impl<'a, O: ByteOrder> AsValueRef<'a> for &'a Compound<O>
Source§impl<'de, O: ByteOrder> Deserialize<'de> for Compound<O>
impl<'de, O: ByteOrder> Deserialize<'de> for Compound<O>
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
impl<AnyO: ByteOrder> ElementTag for Compound<AnyO>
Source§impl<K: AsKey, V: IntoNBT<O>, O: ByteOrder> Extend<(K, V)> for Compound<O>
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)
fn extend<I: IntoIterator<Item = (K, V)>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: T)
fn extend_one(&mut self, item: T)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)