Struct zng_ext_config::SwitchConfig
source · 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) -> BoxedVar<ConfigStatus>
fn status(&self) -> BoxedVar<ConfigStatus>
source§fn get_raw(
&mut self,
key: ConfigKey,
default: RawConfigValue,
insert: bool,
shared: bool,
) -> BoxedVar<RawConfigValue>
fn get_raw( &mut self, key: ConfigKey, default: RawConfigValue, insert: bool, shared: bool, ) -> BoxedVar<RawConfigValue>
key
. Read moresource§fn contains_key(&mut self, key: ConfigKey) -> BoxedVar<bool>
fn contains_key(&mut self, key: ConfigKey) -> BoxedVar<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 Config for SwitchConfig
impl Config for SwitchConfig
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