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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#![doc = include_str!("../README.md")]
pub mod config;
#[cfg(feature = "parsers")]
pub mod parsers;
#[cfg(test)]
mod tests;
pub mod value;
pub use crate::config::{Config, ConfigBuilder};
pub use crate::value::json;
use crate::value::SerdeError;
pub use crate::value::Value;
use std::borrow::Cow;
use std::error::Error as StdError;
use std::fmt::Debug;
use std::result::Result as StdResult;
pub type Result<T> = StdResult<T, Error>;
pub type AnyResult<T> = StdResult<T, Box<dyn StdError>>;
type CowString<'a> = Cow<'a, str>;
type AnyParser = Box<dyn Parse>;
pub const DEFAULT_KEYS_SEPARATOR: &str = ":";
#[non_exhaustive]
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("Empty key path separator")]
EmptySeparator,
#[error("Mapping object expected")]
NotMap,
#[error("Failed to serialize/deserialize")]
SerdeError(#[from] SerdeError),
#[error("Failed to parse value")]
ParseValue(#[from] Box<dyn StdError>),
#[error(transparent)]
IO(#[from] std::io::Error),
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum MergeCase {
Auto,
Sensitive,
Insensitive,
}
impl Default for MergeCase {
fn default() -> Self {
Self::Auto
}
}
pub trait Case {
#[inline]
fn is_case_sensitive(&self) -> bool {
true
}
}
pub trait Parse: Case {
fn parse(&mut self, value: &Value) -> AnyResult<Value>;
}
impl Case for AnyParser {
#[inline]
fn is_case_sensitive(&self) -> bool {
self.as_ref().is_case_sensitive()
}
}
impl Parse for AnyParser {
#[inline]
fn parse(&mut self, value: &Value) -> AnyResult<Value> {
self.as_mut().parse(value)
}
}
#[inline]
fn unicase(data: &str) -> String {
data.to_lowercase()
}
#[inline]
fn normalize_case(data: &str, case_on: bool) -> CowString {
if case_on {
CowString::Borrowed(data)
} else {
CowString::Owned(unicase(data))
}
}