Enum quartz_nbt::NbtTag[][src]

pub enum NbtTag {
    Byte(i8),
    Short(i16),
    Int(i32),
    Long(i64),
    Float(f32),
    Double(f64),
    ByteArray(Vec<i8>),
    String(String),
    List(NbtList),
    Compound(NbtCompound),
    IntArray(Vec<i32>),
    LongArray(Vec<i64>),
}
Expand description

The generic NBT tag type, containing all supported tag variants which wrap around a corresponding rust type.

Variants

Byte(i8)

A signed, one-byte integer.

Short(i16)

A signed, two-byte integer.

Int(i32)

A signed, four-byte integer.

Long(i64)

A signed, eight-byte integer.

Float(f32)

A 32-bit floating point value.

Double(f64)

A 64-bit floating point value.

ByteArray(Vec<i8>)

An array (vec) of signed, one-byte integers.

String(String)

A UTF-8 string.

List(NbtList)

An NBT tag list.

Compound(NbtCompound)

An NBT tag compound.

IntArray(Vec<i32>)

An array (vec) of signed, four-byte integers.

LongArray(Vec<i64>)

An array (vec) of signed, eight-byte integers.

Implementations

impl NbtTag[src]

pub fn type_specifier(&self) -> &str[src]

Returns the single character denoting this tag’s type, or an empty string if this tag type has no type specifier.

Examples

assert_eq!(NbtTag::Long(10).type_specifier(), "L");
assert_eq!(NbtTag::String(String::new()).type_specifier(), "");

// Note that while integers do not require a type specifier, this method will still return "I"
assert_eq!(NbtTag::Int(-10).type_specifier(), "I");

pub fn type_string(&self) -> &'static str[src]

Returns the name of each tag type

Examples

assert_eq!(NbtTag::Float(0.0f32).type_string(), "Float");
assert_eq!(NbtTag::LongArray(Vec::new()).type_string(), "Long Array");

pub fn to_snbt(&self) -> String[src]

Converts this NBT tag into a valid, parsable SNBT string with no extraneous spacing. This method should not be used to generate user-facing text, rather to_component should be used instead.

Examples

Simple primitive conversion:

assert_eq!(NbtTag::Byte(5).to_snbt(), "5B");
assert_eq!(NbtTag::String("\"Quoted text\"".to_owned()).to_snbt(), "'\"Quoted text\"'");

More complex tag conversion:

let mut compound = NbtCompound::new();
compound.insert("foo".to_owned(), vec![-1_i64, -3_i64, -5_i64]);
assert_eq!(NbtTag::Compound(compound).to_snbt(), "{foo:[L;-1,-3,-5]}");

pub fn should_quote(string: &str) -> bool[src]

Returns whether or not the given string needs to be quoted due to non-alphanumeric or otherwise non-standard characters.

pub fn string_to_snbt(string: &str) -> String[src]

Wraps the given string in quotes and escapes any quotes contained in the original string.

Trait Implementations

impl Clone for NbtTag[src]

fn clone(&self) -> NbtTag[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for NbtTag[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl Display for NbtTag[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl From<&'_ String> for NbtTag[src]

fn from(value: &String) -> NbtTag[src]

Performs the conversion.

impl From<&'_ str> for NbtTag[src]

fn from(value: &str) -> NbtTag[src]

Performs the conversion.

impl From<NbtCompound> for NbtTag[src]

fn from(value: NbtCompound) -> NbtTag[src]

Performs the conversion.

impl From<NbtList> for NbtTag[src]

fn from(value: NbtList) -> NbtTag[src]

Performs the conversion.

impl From<String> for NbtTag[src]

fn from(value: String) -> NbtTag[src]

Performs the conversion.

impl<T: NbtRepr> From<T> for NbtTag[src]

fn from(x: T) -> Self[src]

Performs the conversion.

impl From<Vec<i32, Global>> for NbtTag[src]

fn from(value: Vec<i32>) -> NbtTag[src]

Performs the conversion.

impl From<Vec<i64, Global>> for NbtTag[src]

fn from(value: Vec<i64>) -> NbtTag[src]

Performs the conversion.

impl From<Vec<i8, Global>> for NbtTag[src]

fn from(value: Vec<i8>) -> NbtTag[src]

Performs the conversion.

impl From<bool> for NbtTag[src]

fn from(value: bool) -> NbtTag[src]

Performs the conversion.

impl From<f32> for NbtTag[src]

fn from(value: f32) -> NbtTag[src]

Performs the conversion.

impl From<f64> for NbtTag[src]

fn from(value: f64) -> NbtTag[src]

Performs the conversion.

impl From<i16> for NbtTag[src]

fn from(value: i16) -> NbtTag[src]

Performs the conversion.

impl From<i32> for NbtTag[src]

fn from(value: i32) -> NbtTag[src]

Performs the conversion.

impl From<i64> for NbtTag[src]

fn from(value: i64) -> NbtTag[src]

Performs the conversion.

impl From<i8> for NbtTag[src]

fn from(value: i8) -> NbtTag[src]

Performs the conversion.

impl PartialEq<NbtTag> for NbtTag[src]

fn eq(&self, other: &NbtTag) -> bool[src]

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

fn ne(&self, other: &NbtTag) -> bool[src]

This method tests for !=.

impl<'a> TryFrom<&'a NbtTag> for &'a NbtList[src]

type Error = NbtStructureError

The type returned in the event of a conversion error.

fn try_from(tag: &'a NbtTag) -> Result<Self, Self::Error>[src]

Performs the conversion.

impl<'a> TryFrom<&'a NbtTag> for &'a NbtCompound[src]

type Error = NbtStructureError

The type returned in the event of a conversion error.

fn try_from(tag: &'a NbtTag) -> Result<Self, Self::Error>[src]

Performs the conversion.

impl<'a> TryFrom<&'a mut NbtTag> for &'a mut NbtList[src]

type Error = NbtStructureError

The type returned in the event of a conversion error.

fn try_from(tag: &'a mut NbtTag) -> Result<Self, Self::Error>[src]

Performs the conversion.

impl<'a> TryFrom<&'a mut NbtTag> for &'a mut NbtCompound[src]

type Error = NbtStructureError

The type returned in the event of a conversion error.

fn try_from(tag: &'a mut NbtTag) -> Result<Self, Self::Error>[src]

Performs the conversion.

impl TryFrom<NbtTag> for NbtList[src]

type Error = NbtStructureError

The type returned in the event of a conversion error.

fn try_from(tag: NbtTag) -> Result<Self, Self::Error>[src]

Performs the conversion.

impl TryFrom<NbtTag> for NbtCompound[src]

type Error = NbtStructureError

The type returned in the event of a conversion error.

fn try_from(tag: NbtTag) -> Result<Self, Self::Error>[src]

Performs the conversion.

impl StructuralPartialEq for NbtTag[src]

Auto Trait Implementations

impl RefUnwindSafe for NbtTag

impl Send for NbtTag

impl Sync for NbtTag

impl Unpin for NbtTag

impl UnwindSafe for NbtTag

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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]

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

recently added

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

impl<T> ToString for T where
    T: Display + ?Sized
[src]

pub default fn to_string(&self) -> String[src]

Converts the given value to a String. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.