Struct minecraft_assets::api::ModelIdentifier
source · [−]pub struct ModelIdentifier<'a>(_);Expand description
A namespaced identifier for a block or item model.
Prior to 1.13, model identifiers found in
assets/<namespace>/blockstates/*.json did not include a prefix like
block/ or ident/ to disambiguate between different types of models.
Because of this, the minecraft-assets API forces the user to always
specify which type of model they are trying to load (note the existence of
both BlockModel and ItemModel variants in ResourceLocation).
This way, the API will work with versions prior to 1.13.
This struct exists mostly for internal convenience so we can scrap the
leading block/ or item/ if it is included.
Implementations
Returns the name of the model, stripping the leading path component if there is one.
Example
let ident = ModelIdentifier::from("stone");
assert_eq!(ident.model_name(), "stone");
let ident = ModelIdentifier::from("foo:stone");
assert_eq!(ident.model_name(), "stone");
let ident = ModelIdentifier::from("block/oak_planks");
assert_eq!(ident.model_name(), "oak_planks");
let ident = ModelIdentifier::from("foo:block/oak_planks");
assert_eq!(ident.model_name(), "oak_planks");
let ident = ModelIdentifier::from("item/diamond_hoe");
assert_eq!(ident.model_name(), "diamond_hoe");
let ident = ModelIdentifier::from("foo:item/diamond_hoe");
assert_eq!(ident.model_name(), "diamond_hoe");
Methods from Deref<Target = ResourceIdentifier<'a>>
Returns this identifier’s underlying string representation.
Example
let ident = ResourceIdentifier::from("stone");
assert_eq!(ident.as_str(), "stone");
let ident = ResourceIdentifier::from("minecraft:dirt");
assert_eq!(ident.as_str(), "minecraft:dirt");Returns whether or not this resource location includes an explicit namespace.
Example
let id = ResourceIdentifier::from("foo:bar");
assert!(id.has_namespace());
let id = ResourceIdentifier::from("bar");
assert!(!id.has_namespace());Returns the namespace portion of the resource location.
Example
let id = ResourceIdentifier::from("foo:bar");
assert_eq!(id.namespace(), "foo");
let id = ResourceIdentifier::from("bar");
assert_eq!(id.namespace(), "minecraft");
let id = ResourceIdentifier::from(":bar");
assert_eq!(id.namespace(), "");Returns the path portion of the resource location.
Example
let id = ResourceIdentifier::from("foo:bar");
assert_eq!(id.path(), "bar");
let id = ResourceIdentifier::from("bar");
assert_eq!(id.path(), "bar");
let id = ResourceIdentifier::from("foo:");
assert_eq!(id.path(), "");Returns a new identifier with a canonical representation (i.e., containing an explicit namespace).
This will involve allocating a new String if self does not already
contain an explicit namespace.
Examples
Prepends the default namespace when one is not present:
let ident = ResourceIdentifier::from("stone");
let canonical = ident.to_canonical();
assert_eq!(canonical.as_str(), "minecraft:stone");Performs a shallow copy when a namespace is already present:
let ident = ResourceIdentifier::from("foo:bar");
let canonical = ident.to_canonical();
assert_eq!(canonical.as_str(), "foo:bar");
// Prove that it was a cheap copy.
assert_eq!(
ident.as_str().as_ptr() as usize,
canonical.as_str().as_ptr() as usize,
);Returns a new ResourceIdentifier that owns the underlying string.
This is useful for, e.g., storing the identifier in a data structure or passing it to another thread.
By default, all ResourceIdentifiers borrow the string they are
constructed with, so no copying will occur unless you call this
function.
Examples
Constructing an identifier using From simply borrows the data:
let string = String::from("my:ident");
let ident = ResourceIdentifier::from(&string);
// Identifier borrows data from `string`, cannot be sent across threads.
std::thread::spawn(move || println!("{}", ident));Calling into_owned() on the identifier allows it
to be sent to the thread:
let string = String::from("my:ident");
let ident = ResourceIdentifier::from(&string);
let ident = ident.into_owned();
std::thread::spawn(move || println!("{}", ident));Trait Implementations
type Target = ResourceIdentifier<'a>
type Target = ResourceIdentifier<'a>
The resulting type after dereferencing.
Auto Trait Implementations
impl<'a> RefUnwindSafe for ModelIdentifier<'a>
impl<'a> Send for ModelIdentifier<'a>
impl<'a> Sync for ModelIdentifier<'a>
impl<'a> Unpin for ModelIdentifier<'a>
impl<'a> UnwindSafe for ModelIdentifier<'a>
Blanket Implementations
Mutably borrows from an owned value. Read more