cfg_rust_features/
errors.rs

1use std::error::Error;
2use std::fmt;
3
4
5/// Error that occurs when a feature name is unsupported by this crate currently.
6#[derive(Debug)]
7pub struct UnsupportedFeatureTodoError(String);
8
9impl 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, "https://github.com/DerickEddington/cfg_rust_features"
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.)
25pub fn unsupported_feature_todo_error(feature_name: &str) -> UnsupportedFeatureTodoError
26{
27    UnsupportedFeatureTodoError::new(feature_name)
28}
29
30impl Error for UnsupportedFeatureTodoError
31{
32    fn description(&self) -> &str
33    {
34        &self.0
35    }
36}
37
38impl 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)]
56pub struct VersionCheckError;
57
58impl Error for VersionCheckError
59{
60    fn description(&self) -> &str
61    {
62        "version_check error"
63    }
64}
65
66impl 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}