aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2023-03-22 17:58:37 +0000
committermat <github@matdoes.dev>2023-03-22 17:58:37 +0000
commit75e62c913640f4e324912309a05de686cd1d4f7f (patch)
tree6481e2459dd0d24bc7bc018246ea872ce02d126b
parent6738be8090cfe4f9c5af14a45ba8112baf3a04c1 (diff)
downloadazalea-drasl-75e62c913640f4e324912309a05de686cd1d4f7f.tar.xz
use enum-as-inner in nbt
-rw-r--r--Cargo.lock1
-rw-r--r--azalea-nbt/Cargo.toml1
-rwxr-xr-xazalea-nbt/src/tag.rs123
3 files changed, 4 insertions, 121 deletions
diff --git a/Cargo.lock b/Cargo.lock
index d22c9a0f..97028e5a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -354,6 +354,7 @@ dependencies = [
"byteorder",
"compact_str",
"criterion",
+ "enum-as-inner",
"flate2",
"log",
"serde",
diff --git a/azalea-nbt/Cargo.toml b/azalea-nbt/Cargo.toml
index c08d6218..f68e13b0 100644
--- a/azalea-nbt/Cargo.toml
+++ b/azalea-nbt/Cargo.toml
@@ -13,6 +13,7 @@ ahash = { version = "^0.8.3" }
azalea-buf = { path = "../azalea-buf", version = "^0.6.0" }
byteorder = "^1.4.3"
compact_str = { version = "0.7.0", features = ["serde"] }
+enum-as-inner = "0.5.1"
flate2 = "^1.0.25"
log = "0.4.17"
serde = { version = "1.0.152", features = ["derive"], optional = true }
diff --git a/azalea-nbt/src/tag.rs b/azalea-nbt/src/tag.rs
index 4d1e08b8..4661479b 100755
--- a/azalea-nbt/src/tag.rs
+++ b/azalea-nbt/src/tag.rs
@@ -1,11 +1,12 @@
use ahash::AHashMap;
use compact_str::CompactString;
+use enum_as_inner::EnumAsInner;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
/// An NBT value.
-#[derive(Clone, Debug, PartialEq, Default)]
+#[derive(Clone, Debug, PartialEq, Default, EnumAsInner)]
#[repr(u8)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(untagged))]
pub enum Tag {
@@ -35,124 +36,4 @@ impl Tag {
// without offsetting the pointer.
unsafe { *<*const _>::from(self).cast::<u8>() }
}
-
- /// If the type is a byte, return the [`i8`].
- #[inline]
- pub fn as_byte(&self) -> Option<&i8> {
- if let Tag::Byte(v) = self {
- Some(v)
- } else {
- None
- }
- }
-
- /// If the type is a short, return the [`i16`].
- #[inline]
- pub fn as_short(&self) -> Option<&i16> {
- if let Tag::Short(v) = self {
- Some(v)
- } else {
- None
- }
- }
-
- /// If the type is an int, return the [`i32`].
- #[inline]
- pub fn as_int(&self) -> Option<&i32> {
- if let Tag::Int(v) = self {
- Some(v)
- } else {
- None
- }
- }
-
- /// If the type is a long, return the [`i64`].
- #[inline]
- pub fn as_long(&self) -> Option<&i64> {
- if let Tag::Long(v) = self {
- Some(v)
- } else {
- None
- }
- }
-
- /// If the type is a float, return the [`f32`].
- #[inline]
- pub fn as_float(&self) -> Option<&f32> {
- if let Tag::Float(v) = self {
- Some(v)
- } else {
- None
- }
- }
-
- /// If the type is a double, return the [`f64`].
- #[inline]
- pub fn as_double(&self) -> Option<&f64> {
- if let Tag::Double(v) = self {
- Some(v)
- } else {
- None
- }
- }
-
- /// If the type is a string, return the [`str`].
- #[inline]
- pub fn as_string(&self) -> Option<&str> {
- if let Tag::String(v) = self {
- Some(v)
- } else {
- None
- }
- }
-
- /// If the type is a compound, return the `AHashMap<String, Tag>`.
- #[inline]
- pub fn as_compound(&self) -> Option<&AHashMap<CompactString, Tag>> {
- if let Tag::Compound(v) = self {
- Some(v)
- } else {
- None
- }
- }
-
- /// If the type is a bytearray, return the `[u8]`.
- #[inline]
- pub fn as_bytearray(&self) -> Option<&[u8]> {
- if let Tag::ByteArray(v) = self {
- Some(v)
- } else {
- None
- }
- }
-
- /// If the type is an intarray, return the `Vec<i32>`.
- #[inline]
- pub fn as_intarray(&self) -> Option<&Vec<i32>> {
- if let Tag::IntArray(v) = self {
- Some(v)
- } else {
- None
- }
- }
-
- /// If the type is a longarray, return the `Vec<i64>`.
- #[inline]
- pub fn as_longarray(&self) -> Option<&Vec<i64>> {
- if let Tag::LongArray(v) = self {
- Some(v)
- } else {
- None
- }
- }
-
- /// If the type is a list, return the `[Tag]`.
- #[inline]
- pub fn as_list(&self) -> Option<&[Tag]> {
- if let Tag::List(v) = self {
- Some(v)
- } else {
- None
- }
- }
}