Skip to main content

MartDriver

Struct MartDriver 

Source
pub struct MartDriver<'a, S: ShopProvider, const N: usize> {
    pub provider: &'a S,
    pub shop_id: S::ShopId,
    pub money: &'a mut u32,
    pub bag: &'a mut Inventory<S::Item, N>,
}
Expand description

Ready-made MartBackend that routes transactions through the engine’s buy / sell drivers and a ShopProvider.

Suitable for games whose bag is a plain engine Inventory; games with custom bag semantics (overflow spill, key-item rules beyond can_sell, …) implement MartBackend directly.

Fields§

§provider: &'a S§shop_id: S::ShopId§money: &'a mut u32§bag: &'a mut Inventory<S::Item, N>

Trait Implementations§

Source§

impl<S: ShopProvider, const N: usize> MartBackend for MartDriver<'_, S, N>

Source§

type Item = <S as ShopProvider>::Item

Concrete item identifier type.
Source§

fn bag_len(&self) -> usize

Number of occupied bag slots (drives the sell-list cursor).
Source§

fn bag_entry(&self, index: usize) -> Option<(S::Item, u8)>

(item, owned_quantity) at bag slot index, if occupied.
Source§

fn commit_buy(&mut self, item: S::Item, quantity: u8) -> BuyResult

Commit a purchase of quantity × item: add to the bag and deduct the money. On failure nothing may be mutated.
Source§

fn commit_sell(&mut self, bag_index: usize, quantity: u8) -> SellResult

Commit a sale of quantity units of the item at bag_index: remove from the bag and credit the money. On failure nothing may be mutated.
Source§

fn can_buy(&self, item: &Self::Item) -> bool

Whether item may be purchased at all (gates entry into the quantity-select phase). Defaults to true.

Auto Trait Implementations§

§

impl<'a, S, const N: usize> !UnwindSafe for MartDriver<'a, S, N>

§

impl<'a, S, const N: usize> Freeze for MartDriver<'a, S, N>
where &'a S: Freeze, <S as ShopProvider>::ShopId: Freeze, &'a mut Inventory<<S as ShopProvider>::Item, N>: Freeze,

§

impl<'a, S, const N: usize> RefUnwindSafe for MartDriver<'a, S, N>

§

impl<'a, S, const N: usize> Send for MartDriver<'a, S, N>
where &'a S: Send, <S as ShopProvider>::ShopId: Send, &'a mut Inventory<<S as ShopProvider>::Item, N>: Send,

§

impl<'a, S, const N: usize> Sync for MartDriver<'a, S, N>
where &'a S: Sync, <S as ShopProvider>::ShopId: Sync, &'a mut Inventory<<S as ShopProvider>::Item, N>: Sync,

§

impl<'a, S, const N: usize> Unpin for MartDriver<'a, S, N>
where &'a S: Unpin, <S as ShopProvider>::ShopId: Unpin, &'a mut Inventory<<S as ShopProvider>::Item, N>: Unpin,

§

impl<'a, S, const N: usize> UnsafeUnpin for MartDriver<'a, S, N>

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.