Skip to main content

Crate forgeconf

Crate forgeconf 

Source
Expand description

Forgeconf - ergonomic configuration loading for Rust structs.

#[derive(Config)] describes a configuration struct. Loader merges files and other sources in a predictable priority order and converts the result, reporting every bad field at once with its path and origin.

§Example

use forgeconf::Config;

#[derive(Config)]
#[config(file = "examples/fixtures/basic.toml")]
struct AppConfig {
    host: String,
    port: u16,
    #[config(default = 4)]
    workers: u8,
}

let cfg = AppConfig::loader().load()?;
assert_eq!(cfg.host, "localhost");
assert_eq!(cfg.port, 8080);
assert_eq!(cfg.workers, 4); // not in the file: the default applies

§Features

default = ["toml", "cli"]. Parsers: toml, json, yaml. Sources: cli, dotenv. watch reloads on file changes. The crate has no third-party runtime dependency besides its own proc-macro crate.

Modules§

validators
Reusable field validators.

Structs§

ConfigError
Error returned while loading or converting configuration.
ConfigFile
Source backed by a configuration file on disk.
ConfigNode
A node of a configuration tree: a Value plus where it came from.
EnumInfo
Description of an enum type.
FieldInfo
Description of one struct field.
Loader
Merges configuration sources and converts the result into T.
Origin
Where a configuration value came from.
StructInfo
Description of a struct type.
Text
An immutable UTF-8 string that stores up to 22 bytes inline.
VariantInfo
Description of one enum variant.
Warning
A non-fatal finding, such as a deprecated key that is still in use.

Enums§

ErrorKind
What went wrong.
FileFormat
Supported on-disk formats. A variant exists only when its Cargo feature is enabled.
PathSegment
One step on the way from the root to a value.
Shape
What a FromNode type accepts.
Value
The payload of a ConfigNode.

Traits§

Config
A type that knows how to build its own Loader.
ConfigSource
A provider of configuration data, merged by Loader.
FromNode
Trait implemented by types that can be created from a ConfigNode.

Functions§

from_str
Parse input and convert it into T.
parse_str
Parse an in-memory string. Origins name the source <string>.

Type Aliases§

Table
Map of named child nodes.

Derive Macros§

Config
Derive macro for configuration types, next to the Config trait it implements.