risingwave_common/session_config/
visibility_mode.rs1use std::fmt::Formatter;
18use std::str::FromStr;
19
20#[derive(Copy, Default, Debug, Clone, PartialEq, Eq)]
21pub enum VisibilityMode {
22 #[default]
24 Default,
25 All,
27 Checkpoint,
29}
30
31impl FromStr for VisibilityMode {
32 type Err = &'static str;
33
34 fn from_str(s: &str) -> Result<Self, Self::Err> {
35 if s.eq_ignore_ascii_case("all") {
36 Ok(Self::All)
37 } else if s.eq_ignore_ascii_case("checkpoint") {
38 Ok(Self::Checkpoint)
39 } else if s.eq_ignore_ascii_case("default") {
40 Ok(Self::Default)
41 } else {
42 Err("expect one of [all, checkpoint, default]")
43 }
44 }
45}
46
47impl std::fmt::Display for VisibilityMode {
48 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
49 match self {
50 Self::Default => write!(f, "default"),
51 Self::All => write!(f, "all"),
52 Self::Checkpoint => write!(f, "checkpoint"),
53 }
54 }
55}
56
57#[cfg(test)]
58mod tests {
59 use super::*;
60
61 #[test]
62 fn parse_query_mode() {
63 assert_eq!(
64 VisibilityMode::from_str("all").unwrap(),
65 VisibilityMode::All
66 );
67 assert_eq!(
68 VisibilityMode::from_str("All").unwrap(),
69 VisibilityMode::All
70 );
71 assert_eq!(
72 VisibilityMode::from_str("checkpoint").unwrap(),
73 VisibilityMode::Checkpoint
74 );
75 assert_eq!(
76 VisibilityMode::from_str("checkPoint").unwrap(),
77 VisibilityMode::Checkpoint
78 );
79 assert_eq!(
80 VisibilityMode::from_str("default").unwrap(),
81 VisibilityMode::Default
82 );
83 assert!(VisibilityMode::from_str("ab").is_err());
84 }
85}