tf2_enum/
attribute_def.rs1use crate::{DescriptionFormat, EffectType};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5pub struct AttributeDef {
6 pub defindex: u32,
8 pub name: &'static str,
10 pub attribute_class: Option<&'static str>,
12 pub description_string: Option<&'static str>,
14 pub description_format: Option<DescriptionFormat>,
16 pub effect_type: EffectType,
18 pub hidden: bool,
20 pub stored_as_integer: bool,
22}
23
24impl AttributeDef {
25 pub fn description<F>(&self, value: Option<F>) -> Option<String>
27 where
28 F: std::fmt::Display,
29 {
30 let description_string = self.description_string.as_ref()?;
31
32 if let Some(value) = value {
33 return description_string
34 .replace("%s1", &value.to_string())
35 .into();
36 }
37
38 Some(description_string.to_string())
39 }
40}
41
42#[cfg(test)]
43mod tests {
44 use crate::{Attribute, Sheen};
45
46 #[test]
47 fn formats_description() {
48 let sheen = Sheen::TeamShine;
49 let formatted = Sheen::ATTRIBUTE.description(Some(&sheen));
50
51 assert_eq!(formatted, Some("Sheen: Team Shine".into()));
52 }
53}