Port Spam filter to Rust - part 8
This commit is contained in:
@@ -55,7 +55,7 @@ pub struct Rate {
|
||||
pub period: Duration,
|
||||
}
|
||||
|
||||
pub(crate) type Result<T> = std::result::Result<T, String>;
|
||||
pub type Result<T> = std::result::Result<T, String>;
|
||||
|
||||
impl Config {
|
||||
pub async fn resolve_macros(&mut self, classes: &[&str]) {
|
||||
|
||||
@@ -208,6 +208,32 @@ impl Config {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn value_require_non_empty(&mut self, key: impl AsKey) -> Option<&str> {
|
||||
let key = key.as_key();
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
self.keys_read.lock().insert(key.clone());
|
||||
|
||||
if let Some(value) = self.keys.get(&key).and_then(|v| {
|
||||
let v = v.trim();
|
||||
if !v.is_empty() {
|
||||
Some(v)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}) {
|
||||
Some(value)
|
||||
} else {
|
||||
self.errors.insert(
|
||||
key,
|
||||
ConfigError::Parse {
|
||||
error: "Missing property".to_string(),
|
||||
},
|
||||
);
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn try_parse_value<T: ParseValue>(&mut self, key: impl AsKey, value: &str) -> Option<T> {
|
||||
match T::parse_value(value) {
|
||||
Ok(value) => Some(value),
|
||||
|
||||
Reference in New Issue
Block a user