mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 09:07:09 +08:00
refactor: move config defaults from TOML files to Default trait (#352)
This commit is contained in:
@ -353,3 +353,34 @@ impl<A: Send, B> AsyncExt<A, B> for Option<A> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Extension trait for validating application configuration. This trait provides utilities to
|
||||
/// check whether the value is either the default value or is empty.
|
||||
pub trait ConfigExt {
|
||||
/// Returns whether the value of `self` is the default value for `Self`.
|
||||
fn is_default(&self) -> bool
|
||||
where
|
||||
Self: Default + PartialEq<Self>,
|
||||
{
|
||||
*self == Self::default()
|
||||
}
|
||||
|
||||
/// Returns whether the value of `self` is empty after trimming whitespace on both left and
|
||||
/// right ends.
|
||||
fn is_empty_after_trim(&self) -> bool;
|
||||
|
||||
/// Returns whether the value of `self` is the default value for `Self` or empty after trimming
|
||||
/// whitespace on both left and right ends.
|
||||
fn is_default_or_empty(&self) -> bool
|
||||
where
|
||||
Self: Default + PartialEq<Self>,
|
||||
{
|
||||
self.is_default() || self.is_empty_after_trim()
|
||||
}
|
||||
}
|
||||
|
||||
impl ConfigExt for String {
|
||||
fn is_empty_after_trim(&self) -> bool {
|
||||
self.trim().is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user