Struct quartz_nbt::NbtList[][src]

#[repr(transparent)]
pub struct NbtList(_);
Expand description

The NBT tag list type which is essentially just a wrapper for a vec of NBT tags.

This type will implement both Serialize and Deserialize when the serde feature is enabled, however this type should still be read and written with the utilities in the io module when possible if speed is the main priority. See NbtTag for more details.

Implementations

Returns a new NBT tag list with an empty internal vec.

Returns a mutable reference to the internal vector of this NBT list.

Returns the internal vector of this NBT list.

Returns a new NBT tag list with the given initial capacity.

Clones the data in the given list and converts it into an NbtList.

Examples

let list: Vec<i32> = vec![1, 2, 3];
let nbt_list = NbtList::clone_from(&list);
assert_eq!(nbt_list.iter_map::<i32>().flatten().collect::<Vec<i32>>(), list);

Creates an NbtList of NbtCompounds by mapping each element in the given list to its NBT representation.

Iterates over this tag list, converting each tag reference into the specified type.

Examples

let mut list = NbtList::new();
list.push(0i32);
list.push(1i32);
list.push(2.0f64);

let mut iter = list.iter_map::<i32>();
assert!(matches!(iter.next(), Some(Ok(0i32))));
assert!(matches!(iter.next(), Some(Ok(1i32))));
assert!(matches!(iter.next(), Some(Err(..)))); // Type mismatch
assert!(iter.next().is_none());

Iterates over mutable references to the tags in this list, converting each tag reference into the specified type. See iter_map for usage details.

Converts this tag list to a valid SNBT string.

Returns the length of this list.

Returns true if this tag list has a length of zero, false otherwise.

Returns the value of the tag at the given index, or an error if the index is out of bounds or the the tag type does not match the type specified. This method should be used for obtaining primitives and shared references to lists and compounds.

let mut list = NbtList::clone_from(&vec![1i32, 2, 3]);

assert!(matches!(list.get::<i32>(0), Ok(1)));
assert!(list.get::<f64>(0).is_err()); // Type mismatch
assert!(list.get::<i32>(10).is_err()); // Invalid index

Returns a mutable reference to the tag at the given index, or an error if the index is out of bounds or tag type does not match the type specified. This method should be used for obtaining mutable references to elements.

let mut list = NbtList::clone_from(&vec![1i32, 2, 3]);

*list.get_mut::<&mut i32>(0).unwrap() += 1;

assert!(matches!(list.get::<i32>(0), Ok(2)));
assert!(list.get::<f64>(0).is_err()); // Type mismatch
assert!(list.get::<i32>(10).is_err()); // Invalid index

Pushes the given value to the back of the list after wrapping it in an NbtTag.

let mut list = NbtList::new();

list.push(10i32);

assert!(matches!(list.get::<i32>(0), Ok(10)));
assert!(list.get::<f64>(0).is_err()); // Type mismatch
assert!(list.get::<i32>(10).is_err()); // Invalid index

Trait Implementations

Performs the conversion.

Performs the conversion.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

Performs the conversion.

The returned type after indexing.

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

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

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

This method tests for !=.

Serialize this value into the given Serde serializer. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

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

recently added

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

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.