manabrew_engine/spellability/
optional_cost_value.rs1use serde::{Deserialize, Serialize};
6
7use super::optional_cost::OptionalCost;
8
9#[derive(Debug, Clone, Serialize, Deserialize)]
13pub struct OptionalCostValue {
14 pub cost_type: OptionalCost,
15 pub cost_description: String,
16}
17
18impl OptionalCostValue {
19 pub fn new(cost_type: OptionalCost, cost_description: String) -> Self {
20 OptionalCostValue {
21 cost_type,
22 cost_description,
23 }
24 }
25
26 pub fn get_type(&self) -> OptionalCost {
29 self.cost_type
30 }
31
32 pub fn get_cost(&self) -> &str {
35 &self.cost_description
36 }
37}
38
39impl std::fmt::Display for OptionalCostValue {
40 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41 let name = self.cost_type.name();
42 let is_tag = name.starts_with('(');
43 if self.cost_type != OptionalCost::Generic && !is_tag {
44 write!(f, "{} – {}", name, self.cost_description)?;
45 } else if is_tag {
46 write!(f, "{} {}", self.cost_description, name)?;
47 } else {
48 write!(f, "{}", self.cost_description)?;
49 }
50 Ok(())
51 }
52}