[−][src]Module justconfig::item
Structures for representing configuration items and values.
This basic Item
structure is used to create the two fundamental types
of just-config:
The configuration pipeline uses the two types of configuration items at different stages. The configuration pipeline looks like the following:
+--------+ +------------+ +------------+ +----------------+
| source +-->| processors +-->| validators |-->| ValueExtractor |
+--------+ +------------+ +------------+ +----------------+
To make this more transparent take the following example:
let myvalue: u32 = conf.get(ConfPath::from(&["myvalue"])).trim().max(5).value().expect("myvalue not found");
The first part conf.get
searches all registered configuration sources and
returns a Result<StringItem, ConfigError>
.
The following trim()
method is a processor. Processors operate on the
string value of the configuration item and manipulate the string without
knowing anything about the meaning of the string.
The next call is max(5)
. This is a validator. Validators need to know more
about the meaning of the string value. Therefore the first call of validator
converts the Result<StringItem, ConfigError>
into a
Result<TypedItem<T>, ConfigError>
. To make this conversion possible, T must
implement the FromStr
trait.
This conversion is also responsible for the restriction, that all processors have to be placed before the validators within the pipeline.
The last call value()
is implemented via the
ValueExtractor
trait.
The ValueExtractor
can (like validators
) be called on
Result<
StringItem
,
ConfigError
>
or Result<
TypedItem<T>
,
ConfigError
>
. It
extracts the value from the pipeline and returns it to the caller. There are
multiple methods implemented for the ValueExtractor
trait to be able to
return different kinds of values:
- Optional values
- Multiple values
- Single, mandatory values
Structs
StringItem | Newtype for Items while they are passed though the processors of the config pipeline. |
TypedItem | Newtype for Items while they are passed though the validators of the config
pipeline and to the |
Value | Structure representing a configuration value. |
Enums
MapAction |
Traits
SourceLocation | Trait implemented by source location structs provided by data sources. |
ValueExtractor | Trait implemented for |