pub struct SwitchConfig { /* private fields */ }Expand description
Represents multiple config sources that are matched by key.
When a config key is requested a closure defined for each config case in the switch is called, if the closure returns a key the config case is used.
Note that the returned config variables are linked directly with the matched configs,
and if none matches returns from a fallback MemoryConfig. If a config is pushed after no match
the already returned variable will not update to link with the new config.
Implementations§
Source§impl SwitchConfig
impl SwitchConfig
Sourcepub fn push(
&mut self,
match_key: impl Fn(&ConfigKey) -> Option<ConfigKey> + Send + Sync + 'static,
config: impl AnyConfig,
)
pub fn push( &mut self, match_key: impl Fn(&ConfigKey) -> Option<ConfigKey> + Send + Sync + 'static, config: impl AnyConfig, )
Push a config case on the switch.
The match_key closure will be called after the match of previous configs, if it returns Some(key)
the key will be used on the config to retrieve the value variable.
Sourcepub fn push_prefix(&mut self, prefix: impl Into<Txt>, config: impl AnyConfig)
pub fn push_prefix(&mut self, prefix: impl Into<Txt>, config: impl AnyConfig)
Push a config case matched by a key prefix.
The prefix is stripped from the key before it is passed on to the config.
Always matches the config if the prefix is empty.
Sourcepub fn with(
self,
match_key: impl Fn(&ConfigKey) -> Option<ConfigKey> + Send + Sync + 'static,
config: impl AnyConfig,
) -> Self
pub fn with( self, match_key: impl Fn(&ConfigKey) -> Option<ConfigKey> + Send + Sync + 'static, config: impl AnyConfig, ) -> Self
Push the config and return.
See push for more details.
Sourcepub fn with_prefix(self, prefix: impl Into<Txt>, config: impl AnyConfig) -> Self
pub fn with_prefix(self, prefix: impl Into<Txt>, config: impl AnyConfig) -> Self
Push the config and return.
See push_prefix for more details.
Trait Implementations§
Source§impl AnyConfig for SwitchConfig
impl AnyConfig for SwitchConfig
Source§fn status(&self) -> Var<ConfigStatus>
fn status(&self) -> Var<ConfigStatus>
Source§fn get_raw(
&mut self,
key: ConfigKey,
default: RawConfigValue,
insert: bool,
) -> Var<RawConfigValue>
fn get_raw( &mut self, key: ConfigKey, default: RawConfigValue, insert: bool, ) -> Var<RawConfigValue>
key. Read moreSource§fn contains_key(&mut self, key: ConfigKey) -> Var<bool>
fn contains_key(&mut self, key: ConfigKey) -> Var<bool>
key is in the backing storage.Source§fn remove(&mut self, key: &ConfigKey) -> bool
fn remove(&mut self, key: &ConfigKey) -> bool
key from the backing storage. Read moreSource§fn low_memory(&mut self)
fn low_memory(&mut self)
Source§impl Default for SwitchConfig
impl Default for SwitchConfig
Source§fn default() -> SwitchConfig
fn default() -> SwitchConfig
Auto Trait Implementations§
impl Freeze for SwitchConfig
impl !RefUnwindSafe for SwitchConfig
impl Send for SwitchConfig
impl !Sync for SwitchConfig
impl Unpin for SwitchConfig
impl !UnwindSafe for SwitchConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more