pub struct ItemInstance<K, U>where
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> ItemInstance<K, U>where
U: Default,
impl<K, U> ItemInstance<K, U>where
U: Default,
Sourcepub fn new(key: K, quantity: usize) -> ItemInstance<K, U>
pub fn new(key: K, quantity: usize) -> ItemInstance<K, U>
Constructs a new ItemInstance.
Source§impl<K, U> ItemInstance<K, U>
impl<K, U> ItemInstance<K, U>
Sourcepub fn merge<S, U2>(
&mut self,
other: &mut ItemInstance<K, U>,
item_defs: &ItemDefinitions<K, S, U2>,
)where
U2: Default,
pub fn merge<S, U2>(
&mut self,
other: &mut ItemInstance<K, U>,
item_defs: &ItemDefinitions<K, S, U2>,
)where
U2: Default,
Attempts to move as much quantity from other to self as possible.
Trait Implementations§
Source§impl<K, U> Clone for ItemInstance<K, U>
impl<K, U> Clone for ItemInstance<K, U>
Source§fn clone(&self) -> ItemInstance<K, U>
fn clone(&self) -> ItemInstance<K, U>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<K, U> Debug for ItemInstance<K, U>
impl<K, U> Debug for ItemInstance<K, U>
Source§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<ItemInstance<K, U>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<ItemInstance<K, U>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl<K, U> Serialize for ItemInstance<K, U>
impl<K, U> Serialize for ItemInstance<K, U>
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more