Skip to main content

MartBackend

Trait MartBackend 

Source
pub trait MartBackend {
    type Item: Copy + Eq + Hash + Debug;

    // Required methods
    fn bag_len(&self) -> usize;
    fn bag_entry(&self, index: usize) -> Option<(Self::Item, u8)>;
    fn commit_buy(&mut self, item: Self::Item, quantity: u8) -> BuyResult;
    fn commit_sell(&mut self, bag_index: usize, quantity: u8) -> SellResult;

    // Provided method
    fn can_buy(&self, item: &Self::Item) -> bool { ... }
}
Expand description

Price / capacity / transaction callbacks the game supplies to MartState. The state machine owns navigation; the backend owns all money and bag semantics.

Implementations must not mutate anything when a commit fails.

Required Associated Types§

Source

type Item: Copy + Eq + Hash + Debug

Concrete item identifier type.

Required Methods§

Source

fn bag_len(&self) -> usize

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

Source

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

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

Source

fn commit_buy(&mut self, item: Self::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.

Provided Methods§

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.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

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