Trait spirit::helpers::IteratedCfgHelper
source · pub trait IteratedCfgHelper<O, C, Action> {
fn apply<Extractor, ExtractedIter, Name>(
extractor: Extractor,
action: Action,
name: Name,
builder: Builder<O, C>
) -> Builder<O, C>
where
Self: Sized,
Extractor: FnMut(&C) -> ExtractedIter + Send + 'static,
ExtractedIter: IntoIterator<Item = Self>,
Name: Clone + Display + Send + Sync + 'static;
}
Expand description
A variant of the CfgHelper
for resources that come in groups.
If an application should (for example) listen for incoming connections, it is often desirable to be able to configure multiple listening endpoints at once.
In simple words, if the IteratedCfgHelper
is implemented for a type, a CfgHelper
is
implemented for a container of the type (eg. Vec
). The extractor then extracts the vector and
the helper takes care of managing multiple instances of the resource.
Single instance
If a helper is implemented in terms of IteratedCfgHelper
and your application configuration
contains exactly one instance, it is possible to return iter::once
from the extractor, which
will pretend the configuration contains a container of exactly one thing.
Some helper crates may already provide both implementations on the same type in this manner.
Required Methods§
sourcefn apply<Extractor, ExtractedIter, Name>(
extractor: Extractor,
action: Action,
name: Name,
builder: Builder<O, C>
) -> Builder<O, C>where
Self: Sized,
Extractor: FnMut(&C) -> ExtractedIter + Send + 'static,
ExtractedIter: IntoIterator<Item = Self>,
Name: Clone + Display + Send + Sync + 'static,
fn apply<Extractor, ExtractedIter, Name>(
extractor: Extractor,
action: Action,
name: Name,
builder: Builder<O, C>
) -> Builder<O, C>where
Self: Sized,
Extractor: FnMut(&C) -> ExtractedIter + Send + 'static,
ExtractedIter: IntoIterator<Item = Self>,
Name: Clone + Display + Send + Sync + 'static,
Perform the transformation of the builder.
It works the same way as CfgHelper::apply
, only with
slightly different types around the extractor.