Struct game_features::ItemInstance[][src]

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 on ItemInstances

Fields

key: K
Expand description

The key specifies which ItemDefinition defines the properties of this item stack.

quantity: usize
Expand description

The number of items in the stack. Should not be over the associated ItemDefinition::maximum_stack.

durability: Option<usize>
Expand description

The remaining durability of this item, if any. If set to None, it means that the item is unbreakable.

user_data: U
Expand description

The custom user data.

Implementations

impl<K, U: Default> ItemInstance<K, U>[src]

pub fn new(key: K, quantity: usize) -> Self[src]

Constructs a new ItemInstance.

Trait Implementations

impl<K: Clone, U: Clone + Default> Clone for ItemInstance<K, U>[src]

fn clone(&self) -> ItemInstance<K, U>[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<K: Debug, U: Debug + Default> Debug for ItemInstance<K, U>[src]

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

Formats the value using the given formatter. Read more

impl<'de, K, U: Default> Deserialize<'de> for ItemInstance<K, U> where
    K: Deserialize<'de>,
    U: Deserialize<'de>, 
[src]

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

Deserialize this value from the given Serde deserializer. Read more

impl<K, U: Default> Serialize for ItemInstance<K, U> where
    K: Serialize,
    U: Serialize
[src]

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

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

impl<K, U> RefUnwindSafe for ItemInstance<K, U> where
    K: RefUnwindSafe,
    U: RefUnwindSafe

impl<K, U> Send for ItemInstance<K, U> where
    K: Send,
    U: Send

impl<K, U> Sync for ItemInstance<K, U> where
    K: Sync,
    U: Sync

impl<K, U> Unpin for ItemInstance<K, U> where
    K: Unpin,
    U: Unpin

impl<K, U> UnwindSafe for ItemInstance<K, U> where
    K: UnwindSafe,
    U: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.

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