Skip to main content

EquipmentSlots

Struct EquipmentSlots 

Source
pub struct EquipmentSlots<I: Copy + Eq + Hash + Debug, S: Copy + Eq + Hash + Debug> { /* private fields */ }
Expand description

A collection of equipment slots that tracks which item (if any) is equipped in each slot.

§Type parameters

  • I — Item identifier type.
  • S — Slot identifier type (typically EquipSlot<Id> or a game-specific enum).

Implementations§

Source§

impl<I: Copy + Eq + Hash + Debug, S: Copy + Eq + Hash + Debug> EquipmentSlots<I, S>

Source

pub fn new(slots: &[S]) -> Self
where S: Clone,

Create an empty equipment set from the given slots.

All slots start with no item equipped.

Source

pub fn from_pairs(pairs: Vec<(S, I)>) -> Self

Create an equipment set from a list of slot-item pairs.

If a slot appears multiple times the last associated item wins. Any slot not present in pairs will not exist in the resulting set.

Source§

impl<I: Copy + Eq + Hash + Debug, S: Copy + Eq + Hash + Debug> EquipmentSlots<I, S>

Source

pub fn equipped_in(&self, slot: &S) -> Option<&I>

Returns a reference to the item equipped in slot, or None if the slot is empty or does not exist.

Source

pub fn all_equipped(&self) -> Vec<(S, I)>
where S: Clone, I: Clone,

Returns all occupied slot-item pairs.

Source

pub fn is_equipped(&self, item: &I) -> bool

Returns true if item is equipped in any slot.

Source

pub fn slot_count(&self) -> usize

Returns the total number of slots (both occupied and empty).

Source

pub fn iter(&self) -> impl Iterator<Item = &(S, Option<I>)>

Returns an iterator over all slot entries.

Source§

impl<I: Copy + Eq + Hash + Debug, S: Copy + Eq + Hash + Debug> EquipmentSlots<I, S>

Source

pub fn equip(&mut self, slot: S, item: I) -> Result<(), EquipError>

Equip item into slot.

§Errors
Source

pub fn unequip(&mut self, slot: &S) -> Option<I>

Remove and return the item equipped in slot, or None if the slot is empty or does not exist.

Source

pub fn swap(&mut self, a: &S, b: &S) -> Result<(), EquipError>

Swap the items in two slots (including empty ↔ occupied).

§Errors
Source

pub fn clear(&mut self) -> Vec<I>

Unequip all slots and return the previously-equipped items.

After this call every slot is empty.

Trait Implementations§

Source§

impl<I: Clone + Copy + Eq + Hash + Debug, S: Clone + Copy + Eq + Hash + Debug> Clone for EquipmentSlots<I, S>

Source§

fn clone(&self) -> EquipmentSlots<I, S>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<I: Debug + Copy + Eq + Hash + Debug, S: Debug + Copy + Eq + Hash + Debug> Debug for EquipmentSlots<I, S>

Source§

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

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

impl<I: Eq + Copy + Eq + Hash + Debug, S: Eq + Copy + Eq + Hash + Debug> Eq for EquipmentSlots<I, S>

Source§

impl<I: PartialEq + Copy + Eq + Hash + Debug, S: PartialEq + Copy + Eq + Hash + Debug> PartialEq for EquipmentSlots<I, S>

Source§

fn eq(&self, other: &EquipmentSlots<I, S>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<I: PartialEq + Copy + Eq + Hash + Debug, S: PartialEq + Copy + Eq + Hash + Debug> StructuralPartialEq for EquipmentSlots<I, S>

Auto Trait Implementations§

§

impl<I, S> Freeze for EquipmentSlots<I, S>

§

impl<I, S> RefUnwindSafe for EquipmentSlots<I, S>

§

impl<I, S> Send for EquipmentSlots<I, S>
where S: Send, I: Send,

§

impl<I, S> Sync for EquipmentSlots<I, S>
where S: Sync, I: Sync,

§

impl<I, S> Unpin for EquipmentSlots<I, S>
where S: Unpin, I: Unpin,

§

impl<I, S> UnsafeUnpin for EquipmentSlots<I, S>

§

impl<I, S> UnwindSafe for EquipmentSlots<I, S>
where S: UnwindSafe, I: 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.