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 new() -> SwitchConfig
pub fn new() -> SwitchConfig
New default empty.
sourcepub fn push(
&mut self,
match_key: impl Fn(&Txt) -> Option<Txt> + Send + Sync + 'static,
config: impl AnyConfig,
)
pub fn push( &mut self, match_key: impl Fn(&Txt) -> Option<Txt> + 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(&Txt) -> Option<Txt> + Send + Sync + 'static,
config: impl AnyConfig,
) -> SwitchConfig
pub fn with( self, match_key: impl Fn(&Txt) -> Option<Txt> + Send + Sync + 'static, config: impl AnyConfig, ) -> SwitchConfig
Push the config and return.
See push
for more details.
sourcepub fn with_prefix(
self,
prefix: impl Into<Txt>,
config: impl AnyConfig,
) -> SwitchConfig
pub fn with_prefix( self, prefix: impl Into<Txt>, config: impl AnyConfig, ) -> SwitchConfig
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) -> Box<dyn VarBoxed<ConfigStatus>>
fn status(&self) -> Box<dyn VarBoxed<ConfigStatus>>
source§fn get_raw(
&mut self,
key: Txt,
default: RawConfigValue,
insert: bool,
shared: bool,
) -> Box<dyn VarBoxed<RawConfigValue>>
fn get_raw( &mut self, key: Txt, default: RawConfigValue, insert: bool, shared: bool, ) -> Box<dyn VarBoxed<RawConfigValue>>
key
. Read moresource§fn contains_key(&mut self, key: Txt) -> Box<dyn VarBoxed<bool>>
fn contains_key(&mut self, key: Txt) -> Box<dyn VarBoxed<bool>>
key
is in the backing storage.source§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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§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> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§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§impl<T> NoneValue for Twhere
T: Default,
impl<T> NoneValue for Twhere
T: Default,
type NoneType = T
§fn null_value() -> T
fn null_value() -> T
§impl<T> NoneValue for Twhere
T: Default,
impl<T> NoneValue for Twhere
T: Default,
type NoneType = T
§fn null_value() -> T
fn null_value() -> T
§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.