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 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 NbtCompound
s 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.
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
Deserialize this value from the given Serde deserializer. Read more
Performs the conversion.
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
This method tests for !=
.
Auto Trait Implementations
impl RefUnwindSafe for NbtCompound
impl Send for NbtCompound
impl Sync for NbtCompound
impl Unpin for NbtCompound
impl UnwindSafe for NbtCompound
Blanket Implementations
Mutably borrows from an owned value. Read more