id_effect_config 0.4.0

Effect.ts-style ConfigProvider + Figment/serde layers for the workspace `effect` crate
Documentation

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 std::sync::Arc;
use id_effect_config::{Config, MapConfigProvider, config_env, config, ConfigError};
use id_effect::run_blocking;

let p = MapConfigProvider::from_pairs([("HOST", "localhost"), ("PORT", "8080")]);

// Descriptors — nothing is read yet
let host_cfg = Config::string("HOST");
let port_cfg = Config::integer("PORT").with_default(3000);

// Evaluate with a direct provider (synchronous)
let (host, port) = config::all(host_cfg.clone(), port_cfg.clone()).load(&p).unwrap();
assert_eq!(host, "localhost");
assert_eq!(port, 8080);

// Evaluate as Effect with service injection
let env = config_env(p);
let host2: String = run_blocking(host_cfg.run::<String, ConfigError, _>(), env.clone()).unwrap();
let port2: i64 = run_blocking(port_cfg.run::<i64, ConfigError, _>(), env).unwrap();
assert_eq!(host2, "localhost");
assert_eq!(port2, 8080);

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"])
}