/ src / errors.rs
errors.rs
 1  use std::error::Error;
 2  use std::fmt;
 3  
 4  
 5  /// Error that occurs when a feature name is unsupported by this crate currently.
 6  #[derive(Debug)]
 7  pub struct UnsupportedFeatureTodoError(String);
 8  
 9  impl UnsupportedFeatureTodoError
10  {
11      fn new(feature_name: &str) -> Self
12      {
13          UnsupportedFeatureTodoError(format!(
14              "To request support for feature {:?}, open an issue at: {}",
15              feature_name, "rad:zJzhvxB8EJSZRQMAnQeKut83nYXz"
16          ))
17      }
18  }
19  
20  /// Create a new [`UnsupportedFeatureTodoError`].
21  ///
22  /// This exists to avoid `pub`licly exposing [`UnsupportedFeatureTodoError::new`].
23  ///
24  /// (Actually private to the crate, not part of public API.  Is only `pub` for old Rust versions.)
25  pub fn unsupported_feature_todo_error(feature_name: &str) -> UnsupportedFeatureTodoError
26  {
27      UnsupportedFeatureTodoError::new(feature_name)
28  }
29  
30  impl Error for UnsupportedFeatureTodoError
31  {
32      fn description(&self) -> &str
33      {
34          &self.0
35      }
36  }
37  
38  impl fmt::Display for UnsupportedFeatureTodoError
39  {
40      fn fmt<'f>(
41          &self,
42          f: &mut fmt::Formatter<'f>,
43      ) -> fmt::Result
44      {
45          f.write_str(&self.0)
46      }
47  }
48  
49  
50  /// Error that occurs when [`version_check`] fails.
51  ///
52  /// `version_check` does not provide its own error type, so we provide this.
53  ///
54  /// (Actually private to the crate, not part of public API.  Is only `pub` for old Rust versions.)
55  #[derive(Debug)]
56  pub struct VersionCheckError;
57  
58  impl Error for VersionCheckError
59  {
60      fn description(&self) -> &str
61      {
62          "version_check error"
63      }
64  }
65  
66  impl fmt::Display for VersionCheckError
67  {
68      fn fmt<'f>(
69          &self,
70          f: &mut fmt::Formatter<'f>,
71      ) -> fmt::Result
72      {
73          f.write_str(self.description())
74      }
75  }