1
0
Fork 0
mirror of https://github.com/azalea-rs/simdnbt.git synced 2025-08-02 07:26:04 +00:00

add NbtList::as_nbt_tags

This commit is contained in:
mat 2023-12-28 18:30:19 -06:00
parent 922701104a
commit c255ab673a
2 changed files with 120 additions and 0 deletions

View file

@ -304,4 +304,63 @@ impl<'a> NbtList<'a> {
),
}
}
pub fn as_nbt_tags(&self) -> Vec<super::NbtTag> {
match self {
NbtList::Empty => vec![],
NbtList::Byte(bytes) => bytes
.iter()
.map(|&byte| super::NbtTag::Byte(byte))
.collect(),
NbtList::Short(shorts) => shorts
.to_vec()
.into_iter()
.map(|short| super::NbtTag::Short(short))
.collect(),
NbtList::Int(ints) => ints
.to_vec()
.into_iter()
.map(|int| super::NbtTag::Int(int))
.collect(),
NbtList::Long(longs) => longs
.to_vec()
.into_iter()
.map(|long| super::NbtTag::Long(long))
.collect(),
NbtList::Float(floats) => floats
.to_vec()
.into_iter()
.map(|float| super::NbtTag::Float(float))
.collect(),
NbtList::Double(doubles) => doubles
.to_vec()
.into_iter()
.map(|double| super::NbtTag::Double(double))
.collect(),
NbtList::ByteArray(byte_arrays) => byte_arrays
.iter()
.map(|&array| super::NbtTag::ByteArray(array))
.collect(),
NbtList::String(strings) => strings
.iter()
.map(|&string| super::NbtTag::String(string))
.collect(),
NbtList::List(lists) => lists
.iter()
.map(|list| super::NbtTag::List(list.clone()))
.collect(),
NbtList::Compound(compounds) => compounds
.iter()
.map(|compound| super::NbtTag::Compound(compound.clone()))
.collect(),
NbtList::IntArray(int_arrays) => int_arrays
.iter()
.map(|array| super::NbtTag::IntArray(array.clone()))
.collect(),
NbtList::LongArray(long_arrays) => long_arrays
.iter()
.map(|array| super::NbtTag::LongArray(array.clone()))
.collect(),
}
}
}

View file

@ -350,6 +350,67 @@ impl NbtList {
_ => None,
}
}
pub fn as_nbt_tags(&self) -> Vec<super::NbtTag> {
match self {
NbtList::Empty => vec![],
NbtList::Byte(bytes) => bytes
.iter()
.map(|&byte| super::NbtTag::Byte(byte))
.collect(),
NbtList::Short(shorts) => shorts
.to_vec()
.into_iter()
.map(|short| super::NbtTag::Short(short))
.collect(),
NbtList::Int(ints) => ints
.to_vec()
.into_iter()
.map(|int| super::NbtTag::Int(int))
.collect(),
NbtList::Long(longs) => longs
.to_vec()
.into_iter()
.map(|long| super::NbtTag::Long(long))
.collect(),
NbtList::Float(floats) => floats
.to_vec()
.into_iter()
.map(|float| super::NbtTag::Float(float))
.collect(),
NbtList::Double(doubles) => doubles
.to_vec()
.into_iter()
.map(|double| super::NbtTag::Double(double))
.collect(),
NbtList::ByteArray(byte_arrays) => byte_arrays
.iter()
.cloned()
.map(|array| super::NbtTag::ByteArray(array))
.collect(),
NbtList::String(strings) => strings
.iter()
.cloned()
.map(|string| super::NbtTag::String(string))
.collect(),
NbtList::List(lists) => lists
.iter()
.map(|list| super::NbtTag::List(list.clone()))
.collect(),
NbtList::Compound(compounds) => compounds
.iter()
.map(|compound| super::NbtTag::Compound(compound.clone()))
.collect(),
NbtList::IntArray(int_arrays) => int_arrays
.iter()
.map(|array| super::NbtTag::IntArray(array.clone()))
.collect(),
NbtList::LongArray(long_arrays) => long_arrays
.iter()
.map(|array| super::NbtTag::LongArray(array.clone()))
.collect(),
}
}
}
impl From<Vec<i8>> for NbtList {