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.
Implementations
impl NbtCompound
[src]
impl NbtCompound
[src]pub fn into_inner(self) -> HashMap<String, NbtTag>
[src]
pub fn into_inner(self) -> HashMap<String, NbtTag>
[src]Returns the internal hash map of this NBT compound.
pub fn with_capacity(capacity: usize) -> Self
[src]
pub fn with_capacity(capacity: usize) -> Self
[src]Returns a new NBT tag compound with the given initial capacity.
pub fn clone_from<'a, K, V, M>(map: &'a M) -> Self where
K: Clone + Into<String> + 'a,
V: Clone + Into<NbtTag> + 'a,
&'a M: IntoIterator<Item = (&'a K, &'a V)>,
[src]
pub fn clone_from<'a, K, V, M>(map: &'a M) -> Self where
K: Clone + Into<String> + 'a,
V: Clone + Into<NbtTag> + 'a,
&'a M: IntoIterator<Item = (&'a K, &'a V)>,
[src]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 );
pub fn clone_repr_from<'a, K, V, M>(map: &'a M) -> Self where
K: Clone + Into<String> + 'a,
V: NbtRepr + 'a,
&'a M: IntoIterator<Item = (&'a K, &'a V)>,
[src]
pub fn clone_repr_from<'a, K, V, M>(map: &'a M) -> Self where
K: Clone + Into<String> + 'a,
V: NbtRepr + 'a,
&'a M: IntoIterator<Item = (&'a K, &'a V)>,
[src]Creates an NbtCompound
of NbtCompound
s by mapping each element in the given map to its
NBT representation.
pub fn iter_map<'a, T: TryFrom<&'a NbtTag>>(
&'a self
) -> impl Iterator<Item = (&'a str, Result<T, <T as TryFrom<&'a NbtTag>>::Error>)> + 'a
[src]
pub fn iter_map<'a, T: TryFrom<&'a NbtTag>>(
&'a self
) -> impl Iterator<Item = (&'a str, Result<T, <T as TryFrom<&'a NbtTag>>::Error>)> + 'a
[src]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.
pub fn iter_mut_map<'a, T: TryFrom<&'a mut NbtTag>>(
&'a mut self
) -> impl Iterator<Item = (&'a str, Result<T, <T as TryFrom<&'a mut NbtTag>>::Error>)> + 'a
[src]
pub fn iter_mut_map<'a, T: TryFrom<&'a mut NbtTag>>(
&'a mut self
) -> impl Iterator<Item = (&'a str, Result<T, <T as TryFrom<&'a mut NbtTag>>::Error>)> + 'a
[src]Iterates over this tag compound, converting each mutable tag reference into the specified type. See
iter_map
for details.
pub fn is_empty(&self) -> bool
[src]
pub fn is_empty(&self) -> bool
[src]Returns true if the length of this compound is zero, false otherwise.
pub fn get<'a, K: ?Sized, T>(
&'a self,
name: &K
) -> Result<T, NbtReprError<T::Error>> where
String: Borrow<K>,
K: Hash + Eq,
T: TryFrom<&'a NbtTag>,
[src]
pub fn get<'a, K: ?Sized, T>(
&'a self,
name: &K
) -> Result<T, NbtReprError<T::Error>> where
String: Borrow<K>,
K: Hash + Eq,
T: TryFrom<&'a NbtTag>,
[src]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_eq!(compound.get::<_, f64>("test"), Ok(1.0f64)); assert_eq!( compound.get::<_, i32>("test"), Err(NbtReprError::Conversion(NbtStructureError::TypeMismatch)) ); assert_eq!( compound.get::<_, f64>("foo"), Err(NbtReprError::Structure(NbtStructureError::MissingTag)) );
pub fn get_mut<'a, K: ?Sized, T>(
&'a mut self,
name: &K
) -> Result<T, NbtReprError<T::Error>> where
String: Borrow<K>,
K: Hash + Eq,
T: TryFrom<&'a mut NbtTag>,
[src]
pub fn get_mut<'a, K: ?Sized, T>(
&'a mut self,
name: &K
) -> Result<T, NbtReprError<T::Error>> where
String: Borrow<K>,
K: Hash + Eq,
T: TryFrom<&'a mut NbtTag>,
[src]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_eq!(compound.get::<_, f64>("test"), Ok(2.0f64)); assert_eq!( compound.get::<_, i32>("test"), Err(NbtReprError::Conversion(NbtStructureError::TypeMismatch)) ); assert_eq!( compound.get::<_, f64>("foo"), Err(NbtReprError::Structure(NbtStructureError::MissingTag)) );
pub fn contains_key<K: ?Sized>(&self, key: &K) -> bool where
String: Borrow<K>,
K: Hash + Eq,
[src]
pub fn contains_key<K: ?Sized>(&self, key: &K) -> bool where
String: Borrow<K>,
K: Hash + Eq,
[src]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"));
pub fn insert<K: Into<String>, T: Into<NbtTag>>(&mut self, name: K, value: T)
[src]
pub fn insert<K: Into<String>, T: Into<NbtTag>>(&mut self, name: K, value: T)
[src]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_eq!(compound.get::<_, f64>("test"), Ok(1.0f64));
pub fn from_snbt(input: &str) -> Result<Self, ParserError>
[src]
pub fn from_snbt(input: &str) -> Result<Self, ParserError>
[src]Parses a nbt compound from snbt
Example
let tag = NbtCompound::from_snbt(r#"{string:Stuff, list:[I;1,2,3,4,5]}"#).unwrap(); assert_eq!(tag.get::<_, &str>("string"), Ok("Stuff")); assert_eq!(tag.get::<_, &[i32]>("list"), Ok(vec![1,2,3,4,5].as_slice()));
Trait Implementations
impl AsMut<HashMap<String, NbtTag, RandomState>> for NbtCompound
[src]
impl AsMut<HashMap<String, NbtTag, RandomState>> for NbtCompound
[src]impl AsRef<HashMap<String, NbtTag, RandomState>> for NbtCompound
[src]
impl AsRef<HashMap<String, NbtTag, RandomState>> for NbtCompound
[src]impl Clone for NbtCompound
[src]
impl Clone for NbtCompound
[src]fn clone(&self) -> NbtCompound
[src]
fn clone(&self) -> NbtCompound
[src]Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]Performs copy-assignment from source
. Read more
impl Debug for NbtCompound
[src]
impl Debug for NbtCompound
[src]impl Display for NbtCompound
[src]
impl Display for NbtCompound
[src]impl From<NbtCompound> for NbtTag
[src]
impl From<NbtCompound> for NbtTag
[src]fn from(value: NbtCompound) -> NbtTag
[src]
fn from(value: NbtCompound) -> NbtTag
[src]Performs the conversion.
impl PartialEq<NbtCompound> for NbtCompound
[src]
impl PartialEq<NbtCompound> for NbtCompound
[src]fn eq(&self, other: &NbtCompound) -> bool
[src]
fn eq(&self, other: &NbtCompound) -> bool
[src]This method tests for self
and other
values to be equal, and is used
by ==
. Read more
fn ne(&self, other: &NbtCompound) -> bool
[src]
fn ne(&self, other: &NbtCompound) -> bool
[src]This method tests for !=
.
impl<'a> TryFrom<&'a NbtTag> for &'a NbtCompound
[src]
impl<'a> TryFrom<&'a NbtTag> for &'a NbtCompound
[src]impl<'a> TryFrom<&'a mut NbtTag> for &'a mut NbtCompound
[src]
impl<'a> TryFrom<&'a mut NbtTag> for &'a mut NbtCompound
[src]impl TryFrom<NbtTag> for NbtCompound
[src]
impl TryFrom<NbtTag> for NbtCompound
[src]impl StructuralPartialEq for NbtCompound
[src]
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
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn to_owned(&self) -> T
[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
[src]
pub fn clone_into(&self, target: &mut T)
[src]🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more