ItemDefinition

Struct ItemDefinition 

Source
pub struct ItemDefinition<K, S, D: Default> {
    pub key: K,
    pub slot_type: S,
    pub name: String,
    pub friendly_name: String,
    pub description: String,
    pub maximum_stack: Option<usize>,
    pub maximum_durability: Option<usize>,
    pub user_data: D,
}
Expand description

An ItemDefinition stores the different properties of a type of item. It is a schema that contains the data which isn’t changing between different item instances.

Generic Types:

  • K: Type of the key. Usually an enum or a number (ie u32).
  • T: Type of the different item types. For example, an armor-type item can not be placed into a weapon-type inventory slot. If you don’t need to make the distinction between different item types, use the () type.
  • D: The type of the custom user data. If you don’t have any, use the () type. It can (and probably should) be different than the custom user data used on ItemInstances

Fields§

§key: K

The key identifying this item definition.

§slot_type: S

The type / item group that this item definition is part of.

§name: String

The display name of this item definition.

§friendly_name: String

The friendly name of this item definition. Mostly used to find items by name instead of by key.

§description: String

The display description of this item definition.

§maximum_stack: Option<usize>

The maximum number of elements that can be in an item stack. Setting this value to 1 disables the ability to stack this type of item.

§maximum_durability: Option<usize>

The default maximum durability of this item. Setting this to None means that this item type doesn’t use the concept of durability and is unbreakable.

§user_data: D

Custom user data. For example: rarity, weight, list of allowed upgrades, etc…

Implementations§

Source§

impl<K, S, D: Default> ItemDefinition<K, S, D>

Source

pub fn new( key: K, slot_type: S, name: String, friendly_name: String, description: String, maximum_stack: Option<usize>, maximum_durability: Option<usize>, ) -> Self

Constructs a new ItemDefinition.

Trait Implementations§

Source§

impl<K: Clone, S: Clone, D: Clone + Default> Clone for ItemDefinition<K, S, D>

Source§

fn clone(&self) -> ItemDefinition<K, S, D>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<K: Debug, S: Debug, D: Debug + Default> Debug for ItemDefinition<K, S, D>

Source§

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

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

impl<'de, K, S, D> Deserialize<'de> for ItemDefinition<K, S, D>
where K: Deserialize<'de>, S: Deserialize<'de>, D: Deserialize<'de> + Default,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<K, S, D> Serialize for ItemDefinition<K, S, D>
where K: Serialize, S: Serialize, D: Serialize + Default,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<K, S, D> Freeze for ItemDefinition<K, S, D>
where K: Freeze, S: Freeze, D: Freeze,

§

impl<K, S, D> RefUnwindSafe for ItemDefinition<K, S, D>

§

impl<K, S, D> Send for ItemDefinition<K, S, D>
where K: Send, S: Send, D: Send,

§

impl<K, S, D> Sync for ItemDefinition<K, S, D>
where K: Sync, S: Sync, D: Sync,

§

impl<K, S, D> Unpin for ItemDefinition<K, S, D>
where K: Unpin, S: Unpin, D: Unpin,

§

impl<K, S, D> UnwindSafe for ItemDefinition<K, S, D>
where K: UnwindSafe, S: UnwindSafe, D: UnwindSafe,

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<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, 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,