Enum valence_nbt::list::List
source · pub enum List<S = String> {
}
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>
impl<S> List<S>
sourcepub fn element_tag(&self) -> Tag
pub fn element_tag(&self) -> Tag
Returns the element type of this list.
sourcepub fn get(&self, index: usize) -> Option<ValueRef<'_, S>>
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.
sourcepub fn get_mut(&mut self, index: usize) -> Option<ValueMut<'_, S>>
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.
sourcepub fn try_push(&mut self, value: impl Into<Value<S>>) -> bool
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.
sourcepub fn try_insert(&mut self, index: usize, value: impl Into<Value<S>>) -> bool
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.
sourcepub fn remove(&mut self, index: usize) -> Value<S>
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.
sourcepub fn retain<F>(&mut self, f: F)
pub fn retain<F>(&mut self, f: F)
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.