botcat_capoo/error/
unimplemented.rs

1use thiserror::Error;
2
3#[derive(Error, Debug)]
4#[error("{}", self.display_message())]
5pub struct Unimplemented {
6    feature: Option<String>,
7    planned: bool,
8}
9
10impl Default for Unimplemented {
11    fn default() -> Self {
12        Self::new()
13    }
14}
15
16impl Unimplemented {
17    pub fn new() -> Self {
18        Self {
19            feature: None,
20            planned: false,
21        }
22    }
23
24    pub fn feature<S: Into<String>>(feature: S) -> Self {
25        Self {
26            feature: Some(feature.into()),
27            planned: false,
28        }
29    }
30
31    pub fn planned_feature<S: Into<String>>(feature: S) -> Self {
32        Self {
33            feature: Some(feature.into()),
34            planned: true,
35        }
36    }
37
38    pub fn planned_anonymous_feature() -> Self {
39        Self {
40            feature: None,
41            planned: true,
42        }
43    }
44
45    fn display_message(&self) -> String {
46        match (&self.feature, self.planned) {
47            (Some(feature), true) => format!("'{feature}' is planned but not yet implemented"),
48            (Some(feature), false) => format!("'{feature}' is not yet planned"),
49            (None, true) => "This feature is planned but not yet implemented".to_string(),
50            (None, false) => "This feature is not yet planned".to_string(),
51        }
52    }
53}