Skip to main content

manabrew_engine/zone/
cost_payment_stack.rs

1//! CostPaymentStack — tracks cost payments for trigger purposes.
2//!
3//! Mirrors Java's `CostPaymentStack.java`.
4
5/// A simple stack for tracking cost payment instances.
6/// Used mainly by triggers to inspect what costs are being paid.
7/// Mirrors Java's `CostPaymentStack` class.
8#[derive(Debug, Clone, Default)]
9pub struct CostPaymentStack {
10    stack: Vec<CostPaymentEntry>,
11}
12
13/// An individual cost payment entry.
14#[derive(Debug, Clone)]
15pub struct CostPaymentEntry {
16    pub cost_description: String,
17}
18
19impl CostPaymentStack {
20    pub fn new() -> Self {
21        CostPaymentStack { stack: Vec::new() }
22    }
23
24    pub fn push(&mut self, entry: CostPaymentEntry) {
25        self.stack.push(entry);
26    }
27
28    pub fn pop(&mut self) -> Option<CostPaymentEntry> {
29        self.stack.pop()
30    }
31
32    pub fn peek(&self) -> Option<&CostPaymentEntry> {
33        self.stack.last()
34    }
35
36    pub fn clear(&mut self) {
37        self.stack.clear();
38    }
39
40    pub fn iter(&self) -> impl Iterator<Item = &CostPaymentEntry> {
41        self.stack.iter()
42    }
43
44    /// Provides an iterator over entries.
45    /// Mirrors Java's `CostPaymentStack.iterator()`.
46    pub fn iterator(&self) -> impl Iterator<Item = &CostPaymentEntry> {
47        self.stack.iter()
48    }
49}