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§
Required Methods§
Sourcefn bag_entry(&self, index: usize) -> Option<(Self::Item, u8)>
fn bag_entry(&self, index: usize) -> Option<(Self::Item, u8)>
(item, owned_quantity) at bag slot index, if occupied.
Sourcefn commit_buy(&mut self, item: Self::Item, quantity: u8) -> BuyResult
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.
Sourcefn 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.
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".