Struct quartz_nbt::NbtCompound[][src]

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

The NBT tag compound type which is essentially just a wrapper for a hash map of string keys to tag values.

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 compound with an empty internal hash map.

Returns a reference to the internal hash map of this compound.

Returns a mutable reference to the internal hash map of this compound.

Returns the internal hash map of this NBT compound.

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

Clones the data in the given map and converts it into an NbtCompound.

Examples

let mut map = HashMap::new();
map.insert("foo", 10i32);
map.insert("bar", -5i32);

let compound = NbtCompound::clone_from(&map);
assert_eq!(
    compound.get::<_, i32>("foo").unwrap() + compound.get::<_, i32>("bar").unwrap(),
    5i32
);

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

Iterates over this tag compound, converting each tag reference into the specified type. Each key is paired with the result of the attempted conversion into the specified type. The iterator will not terminate even if some conversions fail.

Iterates over this tag compound, converting each mutable tag reference into the specified type. See iter_map for details.

Converts this tag compound into a valid SNBT string.

Returns the number of tags in this compound.

Returns true if the length of this compound is zero, false otherwise.

Returns the value of the tag with the given name, or an error if no tag exists with the given name or specified type. This method should be used to obtain primitives as well as shared references to lists and compounds.

let mut compound = NbtCompound::new();
compound.insert("test", 1.0f64);

assert!((compound.get::<_, f64>("test").unwrap() - 1.0f64).abs() < 1e-5);
assert!(compound.get::<_, i32>("test").is_err()); // Type mismatch
assert!(compound.get::<_, f64>("foo").is_err()); // Missing tag

Returns the value of the tag with the given name, or an error if no tag exists with the given name or specified type. This method should be used to obtain mutable references to lists and compounds.

let mut compound = NbtCompound::new();
compound.insert("test", 1.0f64);

*compound.get_mut::<_, &mut f64>("test").unwrap() *= 2.0;

assert!((compound.get::<_, f64>("test").unwrap() - 2.0f64).abs() < 1e-5);
assert!(compound.get::<_, i32>("test").is_err()); // Type mismatch
assert!(compound.get::<_, f64>("foo").is_err()); // Missing tag

Returns whether or not this compound has a tag with the given name.

let mut compound = NbtCompound::new();
compound.insert("test", 1.0f64);

assert!(compound.contains_key("test"));
assert!(!compound.contains_key("foo"));

Adds the given value to this compound with the given name after wrapping that value in an NbtTag.

let mut compound = NbtCompound::new();
compound.insert("test", 1.0f64);

assert!((compound.get::<_, f64>("test").unwrap() - 1.0f64).abs() < 1e-5);

Parses a nbt compound from snbt

Example

let tag = NbtCompound::from_snbt(r#"{string:Stuff, list:[I;1,2,3,4,5]}"#).unwrap();
assert!(matches!(tag.get::<_, &str>("string"), Ok("Stuff")));
assert_eq!(tag.get::<_, &[i32]>("list").unwrap(), vec![1,2,3,4,5].as_slice());

Trait Implementations

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.

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. 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.