Trait spirit::helpers::CfgHelper

source ·
pub trait CfgHelper<O, C, Action> {
    fn apply<Extractor, Name>(
        extractor: Extractor,
        action: Action,
        name: Name,
        builder: Builder<O, C>
    ) -> Builder<O, C>
    where
        Extractor: FnMut(&C) -> Self + Send + 'static,
        Name: Clone + Display + Send + Sync + 'static
; }
Expand description

A specialized version of Helper for a piece of extracted configuration.

This traits works in tandem with an extractor function and action. The extractor is supposed to extract a specific piece of configuration. The trait is defined on the type returned by the extractor and produces some kind of resource. The action is then performed with the resource.

As an example, the type implementing the trait could be a configuration for a TCP socket. The extractor just pulls out the instance of the type out of the configuration. The action could be whatever the application needs to do with the TCP socket. The helper then bridges these together by making the socket out of the configuration.

The trait often delegates to the basic version of Helper under the hood, by connecting the extractor with the „active“ part of the helper.

You can use the Builder::config_helper to apply a CfgHelper.

TODO

This calls for an example.

Future plans

It is planned to eventually have a custom derive for these kinds of helpers to compose a helper of a bigger piece of configuration. The extractor would then be auto-generated.

Required Methods§

Perform the creation and application of the helper.

Params
  • extractor: Function that pulls out a bit of configuration out of the complete configuration type.
  • action: Something application-specific performed with the resource built of the relevant piece of configuration.
  • name: Named used in logs to reference the specific instance of the type in logs. It is more useful to have „heartbeat connection“ instead of „tcp socket“ in there (often, application has many different kinds of tcp sockets around).
  • builder: The builder to modify by this helper.

Implementors§