diff --git a/simdnbt/src/borrow/list.rs b/simdnbt/src/borrow/list.rs index 647932c..e3e0ca9 100644 --- a/simdnbt/src/borrow/list.rs +++ b/simdnbt/src/borrow/list.rs @@ -304,4 +304,63 @@ impl<'a> NbtList<'a> { ), } } + + pub fn as_nbt_tags(&self) -> Vec { + 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(), + } + } } diff --git a/simdnbt/src/owned/list.rs b/simdnbt/src/owned/list.rs index 4bdf3a7..13a8905 100644 --- a/simdnbt/src/owned/list.rs +++ b/simdnbt/src/owned/list.rs @@ -350,6 +350,67 @@ impl NbtList { _ => None, } } + + pub fn as_nbt_tags(&self) -> Vec { + 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> for NbtList {