Skip to main content

Crate confroid

Crate confroid 

Source
Expand description

§confroid

Your config on ’roids — a small, type-driven reader for environment-based configuration.

Derive Config on a struct and read it with from_env:

#[derive(confroid::Config)]
struct Config {
    #[confroid(default = 8080)]
    port: u16,
}

// Reads the `PORT` environment variable, falling back to 8080.
let config: Config = confroid::from_env().unwrap();

Macros§

from_str_scalar
Register one or more types as confroid scalars (see the docs-disabled variant for details). With the docs feature this also implements Documented, so the type can appear in a config that generates documentation. In that case the type should also implement Display if it is used with a default/example.

Structs§

Ctx
The naming context for the field currently being read.
Env
A snapshot of environment variables.
FieldDoc
A single field in a config’s documentation tree.

Enums§

ConfroidError
The error type returned by from_env and the FromEnv trait.

Traits§

Documented
A type that can describe its configuration shape for documentation.
FromEnv
A type that can be read from the environment at a given Ctx.

Functions§

env_example
Render T as a .env.example-style file.
from_env
Read T from the current process environment.
from_pairs
Read T from an explicit set of variables instead of the process environment. Useful for tests and for reading a curated variable set.
from_snapshot
Read T from an existing Env snapshot.
markdown_table
Render T as a Markdown table of every (leaf) variable.

Type Aliases§

ParserError
A boxed parser error retained as the source of an invalid-value error.
Result
Convenient result alias.

Derive Macros§

Config
Derive confroid::FromEnv for a named struct.
ConfigValue
Derive confroid::FromEnv for a scalar configuration value.