[][src]Module justconfig::processors

Processors trim, split, unescape or otherwise process the configuration items before they get parsed into typed values.

Processors are used to modify configuration items. For an introduction to configuration items see the documentation for the item module.

Processors are implemented as the combination of a trait and an implementation. The trait defines the methods that the processor provides and is always implemented for Result<StringItem, ConfigError>. Each processor method takes an owned self and returns Result<StringItem, ConfigError>. That way processors can be easily chained.

To use a processor just put it after the get method of the Config struct.

defaults.set(conf.root().push_all(&["myvalue"]), "abc", "source info");
conf.add_source(defaults);

let trimed_value: String = conf.get(ConfPath::from(&["myvalue"])).trim().value().unwrap();

Implementing a processor

To implement a new processor first have a look at the source of the existing processors.

For processors there is a helper method within the Item struct. This method is called map.

The processor first checks, if there is an error value within the Result. If there is one, the error is returned without further processing. Then map is called and the result of the mapping operation is returned to the next step of the pipeline. A basic processor looks like this:

use justconfig::error::ConfigError;
use justconfig::item::{StringItem, MapAction};

pub trait Frobnify where Self: Sized {
  fn frobnify(self, frob_count: u8) -> Result<StringItem, ConfigError>;
}

impl Frobnify for Result<StringItem, ConfigError> {
  fn frobnify(self, frob_count: u8) -> Result<StringItem, ConfigError> {
    self?.map(|v| {
      // Your code goes here.
    })
  }
}

Enums

ProcessingError

Traits

Explode

Splits a character delimited config value into multiple configuration values.

NotEmpty

Removes empty config values.

Subst

Substitute placeholders within config values with values (for example environment variables).

Trim

Trims leading, trailing or leading and trailing whitespaces from all config values.

Unescape

Convert escape sequences to special characters.

Unquote

Remove quotes from configuration strings.