1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use std::error::Error;
use std::fmt;


/// Error that occurs when a feature name is unsupported by this crate currently.
#[derive(Debug)]
pub struct UnsupportedFeatureTodoError(String);

impl UnsupportedFeatureTodoError
{
    fn new(feature_name: &str) -> Self
    {
        UnsupportedFeatureTodoError(format!(
            "To request support for feature {:?}, open an issue at: {}",
            feature_name, "https://github.com/DerickEddington/cfg_rust_features"
        ))
    }
}

/// Create a new [`UnsupportedFeatureTodoError`].
///
/// This exists to avoid `pub`licly exposing [`UnsupportedFeatureTodoError::new`].
///
/// (Actually private to the crate, not part of public API.  Is only `pub` for old Rust versions.)
pub fn unsupported_feature_todo_error(feature_name: &str) -> UnsupportedFeatureTodoError
{
    UnsupportedFeatureTodoError::new(feature_name)
}

impl Error for UnsupportedFeatureTodoError
{
    fn description(&self) -> &str
    {
        &self.0
    }
}

impl fmt::Display for UnsupportedFeatureTodoError
{
    fn fmt<'f>(
        &self,
        f: &mut fmt::Formatter<'f>,
    ) -> fmt::Result
    {
        f.write_str(&self.0)
    }
}


/// Error that occurs when [`version_check`] fails.
///
/// `version_check` does not provide its own error type, so we provide this.
///
/// (Actually private to the crate, not part of public API.  Is only `pub` for old Rust versions.)
#[derive(Debug)]
pub struct VersionCheckError;

impl Error for VersionCheckError
{
    fn description(&self) -> &str
    {
        "version_check error"
    }
}

impl fmt::Display for VersionCheckError
{
    fn fmt<'f>(
        &self,
        f: &mut fmt::Formatter<'f>,
    ) -> fmt::Result
    {
        f.write_str(self.description())
    }
}