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) -> Var<ConfigStatus>
fn status(&self) -> Var<ConfigStatus>
Source§fn get_raw(
&mut self,
key: Txt,
default: RawConfigValue,
insert: bool,
) -> Var<RawConfigValue>
fn get_raw( &mut self, key: Txt, default: RawConfigValue, insert: bool, ) -> Var<RawConfigValue>
key. Read moreSource§fn contains_key(&mut self, key: Txt) -> Var<bool>
fn contains_key(&mut self, key: Txt) -> Var<bool>
key is in the backing storage.Source§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> 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> 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().