Enum valence_nbt::list::List

source ·
pub enum List<S = String> {
Show 13 variants End, Byte(Vec<i8>), Short(Vec<i16>), Int(Vec<i32>), Long(Vec<i64>), Float(Vec<f32>), Double(Vec<f64>), ByteArray(Vec<Vec<i8>>), String(Vec<S>), List(Vec<List<S>>), Compound(Vec<Compound<S>>), IntArray(Vec<Vec<i32>>), LongArray(Vec<Vec<i64>>),
}
Expand description

An NBT list value.

NBT lists are homogeneous, meaning each list element must be of the same type. This is opposed to a format like JSON where lists can be heterogeneous. Here is a JSON list that would be illegal in NBT:

[42, "hello", {}]

Every possible element type has its own variant in this enum. As a result, heterogeneous lists are unrepresentable.

Variants§

§

End

The list with the element type of TAG_End and length of zero.

§

Byte(Vec<i8>)

§

Short(Vec<i16>)

§

Int(Vec<i32>)

§

Long(Vec<i64>)

§

Float(Vec<f32>)

§

Double(Vec<f64>)

§

ByteArray(Vec<Vec<i8>>)

§

String(Vec<S>)

§

List(Vec<List<S>>)

§

Compound(Vec<Compound<S>>)

§

IntArray(Vec<Vec<i32>>)

§

LongArray(Vec<Vec<i64>>)

Implementations§

source§

impl<S> List<S>

source

pub fn new() -> Self

Constructs a new empty NBT list, with the element type of TAG_End.

source

pub fn len(&self) -> usize

Returns the length of this list.

source

pub fn is_empty(&self) -> bool

Returns true if this list has no elements. false otherwise.

source

pub fn element_tag(&self) -> Tag

Returns the element type of this list.

source

pub fn get(&self, index: usize) -> Option<ValueRef<'_, S>>

Gets a reference to the value at the given index in this list, or None if the index is out of bounds.

source

pub fn get_mut(&mut self, index: usize) -> Option<ValueMut<'_, S>>

Gets a mutable reference to the value at the given index in this list, or None if the index is out of bounds.

source

pub fn try_push(&mut self, value: impl Into<Value<S>>) -> bool

Attempts to add the given value to the end of this list, failing if adding the value would result in the list not being heterogeneous (have multiple types inside it). Returns true if the value was added, false otherwise.

source

pub fn try_insert(&mut self, index: usize, value: impl Into<Value<S>>) -> bool

Attempts to insert the given value at the given index in this list, failing if adding the value would result in the list not being heterogeneous (have multiple types inside it). Returns true if the value was added, false otherwise.

Panics

Panics if the index is greater than the length of the list.

source

pub fn remove(&mut self, index: usize) -> Value<S>

Removes the element at the given index in the list, and returns the value removed.

Panics

Panics if index is out of bounds.

source

pub fn retain<F>(&mut self, f: F)
where F: FnMut(ValueMut<'_, S>) -> bool,

Returns only the elements specified by the predicate, passing a mutable reference to it.

In other words, removes all elements e such that f(ValueMut(&mut e)) returns false. This method operates in place, visiting each element exactly once in the original order, and preserves the order of the retained elements.

source

pub fn iter(&self) -> Iter<'_, S>

Returns an iterator over this list. This iterator yields ValueRefs.

source

pub fn iter_mut(&mut self) -> IterMut<'_, S>

Returns a mutable iterator over this list. This iterator yields ValueMuts.

Trait Implementations§

source§

impl<S: Clone> Clone for List<S>

source§

fn clone(&self) -> List<S>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<S: Debug> Debug for List<S>

source§

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

Formats the value using the given formatter. Read more
source§

impl<S> Default for List<S>

source§

fn default() -> List<S>

Returns the “default value” for a type. Read more
source§

impl<'a, S> From<&'a List<S>> for ValueRef<'a, S>

source§

fn from(v: &'a List<S>) -> Self

Converts to this type from the input type.
source§

impl<'a, S> From<&'a mut List<S>> for ValueMut<'a, S>

source§

fn from(v: &'a mut List<S>) -> Self

Converts to this type from the input type.
source§

impl<S> From<List<S>> for Value<S>

source§

fn from(v: List<S>) -> Self

Converts to this type from the input type.
source§

impl<S> From<Value<S>> for List<S>

Converts a value to a singleton list.

source§

fn from(value: Value<S>) -> Self

Converts to this type from the input type.
source§

impl<S> From<Vec<Compound<S>>> for List<S>

source§

fn from(v: Vec<Compound<S>>) -> Self

Converts to this type from the input type.
source§

impl<'a> From<Vec<Cow<'a, str>>> for List<Cow<'a, str>>

source§

fn from(v: Vec<Cow<'a, str>>) -> Self

Converts to this type from the input type.
source§

impl<S> From<Vec<List<S>>> for List<S>

source§

fn from(v: Vec<List<S>>) -> Self

Converts to this type from the input type.
source§

impl From<Vec<String>> for List<String>

source§

fn from(v: Vec<String>) -> Self

Converts to this type from the input type.
source§

impl<S> From<Vec<Vec<i32>>> for List<S>

source§

fn from(v: Vec<Vec<i32>>) -> Self

Converts to this type from the input type.
source§

impl<S> From<Vec<Vec<i64>>> for List<S>

source§

fn from(v: Vec<Vec<i64>>) -> Self

Converts to this type from the input type.
source§

impl<S> From<Vec<Vec<i8>>> for List<S>

source§

fn from(v: Vec<Vec<i8>>) -> Self

Converts to this type from the input type.
source§

impl<S> From<Vec<f32>> for List<S>

source§

fn from(v: Vec<f32>) -> Self

Converts to this type from the input type.
source§

impl<S> From<Vec<f64>> for List<S>

source§

fn from(v: Vec<f64>) -> Self

Converts to this type from the input type.
source§

impl<S> From<Vec<i16>> for List<S>

source§

fn from(v: Vec<i16>) -> Self

Converts to this type from the input type.
source§

impl<S> From<Vec<i32>> for List<S>

source§

fn from(v: Vec<i32>) -> Self

Converts to this type from the input type.
source§

impl<S> From<Vec<i64>> for List<S>

source§

fn from(v: Vec<i64>) -> Self

Converts to this type from the input type.
source§

impl<S> From<Vec<i8>> for List<S>

source§

fn from(v: Vec<i8>) -> Self

Converts to this type from the input type.
source§

impl<'a, S> IntoIterator for &'a List<S>

§

type Item = ValueRef<'a, S>

The type of the elements being iterated over.
§

type IntoIter = Iter<'a, S>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'a, S> IntoIterator for &'a mut List<S>

§

type Item = ValueMut<'a, S>

The type of the elements being iterated over.
§

type IntoIter = IterMut<'a, S>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<S> IntoIterator for List<S>

§

type Item = Value<S>

The type of the elements being iterated over.
§

type IntoIter = IntoIter<S>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<S> PartialEq for List<S>
where S: Ord + Hash,

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl<S> RefUnwindSafe for List<S>
where S: RefUnwindSafe,

§

impl<S> Send for List<S>
where S: Send,

§

impl<S> Sync for List<S>
where S: Sync,

§

impl<S> Unpin for List<S>
where S: Unpin,

§

impl<S> UnwindSafe for List<S>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

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

Performs the conversion.