Skip to main content

Identifier

Struct Identifier 

Source
pub struct Identifier {
    pub namespace: String,
    pub path: String,
}
Expand description

A namespaced identifier in the format namespace:path.

Identifiers (also called ResourceLocations) are used throughout the Minecraft protocol to reference game content: blocks (minecraft:stone), items (minecraft:diamond), entities (minecraft:creeper), dimensions (minecraft:overworld), registries, and plugin channels. They are encoded on the wire as a single VarInt-prefixed UTF-8 string in the format namespace:path.

The namespace defaults to minecraft when absent. Valid characters are:

  • Namespace: [a-z0-9._-]
  • Path: [a-z0-9._-/]

Fields§

§namespace: String

The namespace part (e.g., minecraft, mymod).

§path: String

The path part (e.g., stone, textures/block/dirt).

Implementations§

Source§

impl Identifier

Source

pub fn new( namespace: impl Into<String>, path: impl Into<String>, ) -> Result<Self>

Creates a new identifier with the given namespace and path.

Validates that both namespace and path contain only allowed characters. Returns Error::InvalidData if validation fails.

Source

pub fn minecraft(path: impl Into<String>) -> Result<Self>

Creates a new identifier under the minecraft namespace.

This is a convenience for the most common case, since the majority of identifiers in the protocol use the minecraft namespace.

Source

pub fn as_str(&self) -> String

👎Deprecated:

use Display impl via to_string() instead

Returns the full identifier string in namespace:path format.

Note: this allocates a new String. For zero-cost display, use the Display impl via format!("{id}") or id.to_string().

Trait Implementations§

Source§

impl Clone for Identifier

Source§

fn clone(&self) -> Identifier

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Identifier

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Decode for Identifier

Decodes an Identifier from a VarInt-prefixed UTF-8 string.

Reads the string using the standard Minecraft string decoding, then parses it as namespace:path. If no colon is present, the namespace defaults to minecraft. Validates that all characters are in the allowed sets for namespace and path.

Source§

fn decode(buf: &mut &[u8]) -> Result<Self>

Reads a protocol string and parses it as an identifier.

Fails with Error::InvalidData if the identifier contains invalid characters or is empty. Also inherits string decoding errors (buffer underflow, string too long, invalid UTF-8).

Source§

impl Display for Identifier

Displays the identifier in namespace:path format.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Encode for Identifier

Encodes an Identifier as a VarInt-prefixed UTF-8 string in namespace:path format.

The full namespace:path string is written using the standard Minecraft string encoding (VarInt length prefix + UTF-8 bytes). This is the same wire format used for all string fields in the protocol.

Source§

fn encode(&self, buf: &mut Vec<u8>) -> Result<()>

Writes the identifier as a VarInt-prefixed namespace:path string.

Source§

impl EncodedSize for Identifier

Computes the wire size of the identifier in namespace:path format.

The total size includes the VarInt length prefix and the full namespace:path UTF-8 byte count (including the colon separator).

Source§

fn encoded_size(&self) -> usize

Returns the VarInt prefix size plus the byte length of namespace:path.

Source§

impl Eq for Identifier

Source§

impl Hash for Identifier

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Identifier

Source§

fn eq(&self, other: &Identifier) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Identifier

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.