castep_cell_io/param/general/
write_formatted_potential.rs1use castep_cell_fmt::{Cell, CellValue, ToCell, ToCellValue, CResult};
2use castep_cell_fmt::parse::FromKeyValue;
3use castep_cell_fmt::query::value_as_bool;
4
5#[derive(Default, Debug, Clone, Copy, PartialEq, Eq)]
14pub struct WriteFormattedPotential(pub bool);
15
16impl FromKeyValue for WriteFormattedPotential {
17 const KEY_NAME: &'static str = "WRITE_FORMATTED_POTENTIAL";
18
19 fn from_cell_value_kv(value: &CellValue<'_>) -> CResult<Self> {
20 Ok(Self(value_as_bool(value)?))
21 }
22}
23
24impl ToCell for WriteFormattedPotential {
25 fn to_cell(&self) -> Cell<'_> {
26 Cell::KeyValue("WRITE_FORMATTED_POTENTIAL", CellValue::Bool(self.0))
27 }
28}
29
30impl ToCellValue for WriteFormattedPotential {
31 fn to_cell_value(&self) -> CellValue<'_> {
32 CellValue::Bool(self.0)
33 }
34}
35
36#[cfg(test)]
37mod tests {
38 use super::*;
39
40 #[test]
41 fn test_from_cell_value_true() {
42 let val = CellValue::Bool(true);
43 assert_eq!(WriteFormattedPotential::from_cell_value_kv(&val).unwrap().0, true);
44 }
45
46 #[test]
47 fn test_from_cell_value_false() {
48 let val = CellValue::Bool(false);
49 assert_eq!(WriteFormattedPotential::from_cell_value_kv(&val).unwrap().0, false);
50 }
51
52 #[test]
53 fn test_key_name() {
54 assert_eq!(WriteFormattedPotential::KEY_NAME, "WRITE_FORMATTED_POTENTIAL");
55 }
56}
57