pub struct ItemInstance<K, U: Default> {
pub key: K,
pub quantity: usize,
pub durability: Option<usize>,
pub user_data: U,
}Expand description
An ItemInstance is a stack of item.
It refers to the ItemDefinition’s key. The associated ItemDefinition contains the data
describing that object type.
An item stack can be composed of one or many of the same item.
It can also have a durability, which decreases when the item is used using
Inventory::use_item.
Custom data can be added into the user_data field. This data is specific to each item instance.
Generic Types:
- K: Type of the key. Usually an enum or a number (ie u32).
- U: 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 onItemInstances
Fields§
§key: KThe key specifies which ItemDefinition defines the properties of this item stack.
quantity: usizeThe number of items in the stack.
Should not be over the associated ItemDefinition::maximum_stack.
durability: Option<usize>The remaining durability of this item, if any. If set to None, it means that the item is unbreakable.
user_data: UThe custom user data.
Implementations§
Source§impl<K, U: Default> ItemInstance<K, U>
impl<K, U: Default> ItemInstance<K, U>
Trait Implementations§
Source§impl<K: Clone, U: Clone + Default> Clone for ItemInstance<K, U>
impl<K: Clone, U: Clone + Default> Clone for ItemInstance<K, U>
Source§fn clone(&self) -> ItemInstance<K, U>
fn clone(&self) -> ItemInstance<K, U>
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<'de, K, U> Deserialize<'de> for ItemInstance<K, U>
impl<'de, K, U> Deserialize<'de> for ItemInstance<K, U>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl<K, U> Freeze for ItemInstance<K, U>
impl<K, U> RefUnwindSafe for ItemInstance<K, U>where
K: RefUnwindSafe,
U: RefUnwindSafe,
impl<K, U> Send for ItemInstance<K, U>
impl<K, U> Sync for ItemInstance<K, U>
impl<K, U> Unpin for ItemInstance<K, U>
impl<K, U> UnwindSafe for ItemInstance<K, U>where
K: UnwindSafe,
U: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more