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
pub mod app_name;
pub use app_name::EnvironmentVariableAppNameProvider;
use std::error::Error;
use std::fmt::{Display, Formatter};
pub mod credentials;
pub use credentials::EnvironmentVariableCredentialsProvider;
pub mod region;
pub use region::EnvironmentVariableRegionProvider;
#[derive(Debug)]
pub(crate) struct InvalidBooleanValue {
value: String,
}
impl Display for InvalidBooleanValue {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{} was not a valid boolean", self.value)
}
}
impl Error for InvalidBooleanValue {}
pub(crate) fn parse_bool(value: &str) -> Result<bool, InvalidBooleanValue> {
if value.eq_ignore_ascii_case("false") {
Ok(false)
} else if value.eq_ignore_ascii_case("true") {
Ok(true)
} else {
Err(InvalidBooleanValue {
value: value.to_string(),
})
}
}