diff options
| author | mat <git@matdoes.dev> | 2026-01-06 02:05:47 -1100 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2026-01-06 02:05:47 -1100 |
| commit | 4c61a41476e383d8fb765790bd3dd65e4019c0f4 (patch) | |
| tree | af116e49fa33d2e6a6004f45364a642370898f91 /azalea-registry/src | |
| parent | fdbcfaab4813da928f9f27e119d4951088c3a853 (diff) | |
| download | azalea-drasl-4c61a41476e383d8fb765790bd3dd65e4019c0f4.tar.xz | |
fix identifier partialeq/hash and add Client::resolve_registry_key
Diffstat (limited to 'azalea-registry/src')
| -rw-r--r-- | azalea-registry/src/data.rs | 3 | ||||
| -rw-r--r-- | azalea-registry/src/identifier.rs | 17 | ||||
| -rw-r--r-- | azalea-registry/src/lib.rs | 1 |
3 files changed, 20 insertions, 1 deletions
diff --git a/azalea-registry/src/data.rs b/azalea-registry/src/data.rs index b2c3691b..a8e2d304 100644 --- a/azalea-registry/src/data.rs +++ b/azalea-registry/src/data.rs @@ -72,6 +72,9 @@ macro_rules! data_registry { impl crate::DataRegistryKey for $enum_name { type Borrow<'a> = $enum_name<&'a Identifier>; + fn from_ident(ident: Identifier) -> Self { + Self::from(ident) + } fn into_ident(self) -> Identifier { match self { $( diff --git a/azalea-registry/src/identifier.rs b/azalea-registry/src/identifier.rs index 635c5935..4f906181 100644 --- a/azalea-registry/src/identifier.rs +++ b/azalea-registry/src/identifier.rs @@ -2,6 +2,7 @@ use std::{ fmt::{self, Debug, Display}, + hash::{Hash, Hasher}, io::{self, Cursor, Write}, num::NonZeroUsize, str::FromStr, @@ -18,7 +19,7 @@ use simdnbt::{FromNbtTag, ToNbtTag, owned::NbtTag}; /// /// This was formerly called a `ResourceLocation`. #[doc(alias = "ResourceLocation")] -#[derive(Clone, Default, Eq, Hash, PartialEq)] +#[derive(Clone, Default, Eq)] pub struct Identifier { // empty namespaces aren't allowed so NonZero is fine. colon_index: Option<NonZeroUsize>, @@ -63,6 +64,20 @@ impl Identifier { } } } +impl PartialEq for Identifier { + fn eq(&self, other: &Self) -> bool { + self.namespace() == other.namespace() && self.path() == other.path() + } +} +impl Hash for Identifier { + fn hash<H: Hasher>(&self, state: &mut H) { + let namespace = self.namespace(); + if namespace != DEFAULT_NAMESPACE { + namespace.hash(state); + } + self.path().hash(state); + } +} impl Display for Identifier { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/azalea-registry/src/lib.rs b/azalea-registry/src/lib.rs index e5157e4f..1d146508 100644 --- a/azalea-registry/src/lib.rs +++ b/azalea-registry/src/lib.rs @@ -319,6 +319,7 @@ pub trait DataRegistry: pub trait DataRegistryKey { type Borrow<'a>: DataRegistryKeyRef<'a>; + fn from_ident(ident: Identifier) -> Self; fn into_ident(self) -> Identifier; } pub trait DataRegistryKeyRef<'a> { |
