Configuration loading in three complementary styles, aligned with Effect.ts configuration:
1. Config<T> descriptor (Effect Config.string / Config.withDefault / Config.all)
The recommended approach. Compose lazy descriptors, then evaluate with [Config::run]
(service-injected) or [Config::load] (direct provider reference):
use Arc;
use ;
use run_blocking;
let p = from_pairs;
// Descriptors — nothing is read yet
let host_cfg = string;
let port_cfg = integer.with_default;
// Evaluate with a direct provider (synchronous)
let = all.load.unwrap;
assert_eq!;
assert_eq!;
// Evaluate as Effect with service injection
let env = config_env;
let host2: String = run_blocking.unwrap;
let port2: i64 = run_blocking.unwrap;
assert_eq!;
assert_eq!;
2. Figment + serde (whole-document extract)
Build a Figment (layering TOML, JSON, env, …), then [extract] /
[FigmentLayer] — good for structured config files.
3. Low-level Effect reads via load::read_* with Needs<ConfigProvider>
Inject the provider via the effect environment and call the free functions directly:
use id_effect_config::{read_string, ConfigError};
use id_effect::Needs;
fn load_host<A, E, R>() -> ::id_effect::Effect<A, E, R>
where
A: From<String> + 'static,
E: From<ConfigError> + 'static,
R: id_effect::Needs<id_effect_config::ConfigProvider> + 'static,
{
read_string(&["HOST"])
}