Skip to main content

manabrew_engine/cost/
trait_cost_visitor.rs

1//! Cost visitor abstraction for parity with Java `ICostVisitor<T>`.
2
3use crate::agent::PlayerAgent;
4use crate::cost::payment_decision::PaymentDecision;
5use crate::cost::CostPart;
6use crate::game::GameState;
7use crate::ids::{CardId, PlayerId};
8
9pub trait CostVisitor<T> {
10    fn visit(
11        &mut self,
12        player: PlayerId,
13        source: CardId,
14        cost_part: &CostPart,
15        game: &GameState,
16    ) -> Option<T>;
17}
18
19impl<T> CostVisitor<PaymentDecision> for T
20where
21    T: PlayerAgent + ?Sized,
22{
23    fn visit(
24        &mut self,
25        player: PlayerId,
26        source: CardId,
27        cost_part: &CostPart,
28        game: &GameState,
29    ) -> Option<PaymentDecision> {
30        self.decide_cost_part(player, source, cost_part, game)
31    }
32}