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§
- Config
Error - Error returned while loading or converting configuration.
- Config
File - Source backed by a configuration file on disk.
- Config
Node - A node of a configuration tree: a
Valueplus where it came from. - Enum
Info - Description of an enum type.
- Field
Info - Description of one struct field.
- Loader
- Merges configuration sources and converts the result into
T. - Origin
- Where a configuration value came from.
- Struct
Info - Description of a struct type.
- Text
- An immutable UTF-8 string that stores up to 22 bytes inline.
- Variant
Info - Description of one enum variant.
- Warning
- A non-fatal finding, such as a deprecated key that is still in use.
Enums§
- Error
Kind - What went wrong.
- File
Format - Supported on-disk formats. A variant exists only when its Cargo feature is enabled.
- Path
Segment - One step on the way from the root to a value.
- Shape
- What a
FromNodetype accepts. - Value
- The payload of a
ConfigNode.
Traits§
- Config
- A type that knows how to build its own
Loader. - Config
Source - A provider of configuration data, merged by
Loader. - From
Node - Trait implemented by types that can be created from a
ConfigNode.
Functions§
- from_
str - Parse
inputand convert it intoT. - parse_
str - Parse an in-memory string. Origins name the source
<string>.
Type Aliases§
- Table
- Map of named child nodes.