castep_param_io/param/general/
write_checkpoint.rs1use std::fmt::Display;
2
3use castep_param_derive::KeywordDisplay;
4use serde::{Deserialize, Serialize};
5
6
7#[derive(
8 Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, KeywordDisplay,
9)]
10#[keyword_display(field = "WRITE_CHECKPOINT")]
11pub enum WriteCheckpoint {
12 Value(WriteCheckpointValue),
13 Option(WriteCheckpointOption),
14}
15
16impl Default for WriteCheckpoint {
17 fn default() -> Self {
18 Self::Value(WriteCheckpointValue::All)
19 }
20}
21
22impl From<WriteCheckpointValue> for WriteCheckpoint {
23 fn from(value: WriteCheckpointValue) -> Self {
24 Self::Value(value)
25 }
26}
27
28impl From<WriteCheckpointOption> for WriteCheckpoint {
29 fn from(value: WriteCheckpointOption) -> Self {
30 Self::Option(value)
31 }
32}
33
34#[derive(
35 Debug, Clone, Copy, Default, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize,
36)]
37
38pub enum WriteCheckpointValue {
39 None,
40 Minimal,
41 Both,
42 #[default]
43 All,
44 Full,
45}
46
47impl Display for WriteCheckpointValue {
48 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
49 match self {
50 WriteCheckpointValue::None => f.write_str("NONE"),
51 WriteCheckpointValue::Minimal => f.write_str("MINIMAL"),
52 WriteCheckpointValue::Both => f.write_str("bOTH"),
53 WriteCheckpointValue::All => f.write_str("ALL"),
54 WriteCheckpointValue::Full => f.write_str("fULL"),
55 }
56 }
57}
58
59#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
60pub enum WriteCheckpointOption {
61 Success(WriteCheckpointValue),
62 Failure(WriteCheckpointValue),
63 Backup(WriteCheckpointValue),
64}
65
66impl Default for WriteCheckpointOption {
67 fn default() -> Self {
68 Self::Backup(WriteCheckpointValue::Minimal)
69 }
70}
71
72impl Display for WriteCheckpointOption {
73 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
74 match self {
75 WriteCheckpointOption::Success(v) => write!(f, "SUCCESS={v}"),
76 WriteCheckpointOption::Failure(v) => write!(f, "FAILURE={v}"),
77 WriteCheckpointOption::Backup(v) => write!(f, "BACKUP={v}"),
78 }
79 }
80}
81
82#[cfg(test)]
83mod test {
84 use crate::param::{general::write_checkpoint::WriteCheckpointOption, KeywordDisplay};
85
86 use super::WriteCheckpoint;
87
88 #[test]
89 fn write_checkpoint() {
90 let write_checkpoint = WriteCheckpoint::default();
91 assert_eq!("WRITE_CHECKPOINT : ALL", write_checkpoint.output());
92 let write_checkpoint_option = WriteCheckpoint::Option(WriteCheckpointOption::default());
93 assert_eq!(
94 "WRITE_CHECKPOINT : BACKUP=MINIMAL",
95 write_checkpoint_option.output()
96 );
97 }
98}