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>
impl<S: ShopProvider, const N: usize> MartBackend for MartDriver<'_, S, N>
Source§type Item = <S as ShopProvider>::Item
type Item = <S as ShopProvider>::Item
Concrete item identifier type.
Source§fn bag_entry(&self, index: usize) -> Option<(S::Item, u8)>
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
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
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.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>where
&'a S: RefUnwindSafe,
<S as ShopProvider>::ShopId: RefUnwindSafe,
&'a mut Inventory<<S as ShopProvider>::Item, N>: RefUnwindSafe,
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>where
&'a S: UnsafeUnpin,
<S as ShopProvider>::ShopId: UnsafeUnpin,
&'a mut Inventory<<S as ShopProvider>::Item, N>: UnsafeUnpin,
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