Expand description
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"])
}Modules§
- config
- Mirrors
import { Config } from "effect"— scalars, combinators, and free functions. - figment
- Common
Figmentbuilders.
Structs§
- Config
- A lazy, composable configuration descriptor (Effect.ts
Config<T>). - Config
Provider Service - Injectable wrapper around an
Arc<dyn ConfigProvider>. - EnvConfig
Provider - Reads from
std::envusing flattened keys (SERVER_PORTfor path["SERVER","PORT"]with default delim). - EnvConfig
Provider Live std::envConfigProviderwith defaultProviderOptions.- Figment
Config Provider - Adapts a merged
Figmentas a provider (paths joined with., matching Figment key paths). - Figment
Layer - Deserializes
Tfrom a sharedFigmenton eachbuild. - MapConfig
Provider - In-memory map for tests or static overrides (
ConfigProvider.fromMap). - OrElse
Config Provider - Try
primaryfirst; if it returnsNone, usefallback(Effect-style provider composition). - Provider
Options - Options aligned with Effect
ConfigProvider.fromEnv(pathDelim,seqDelim). - Scoped
Config Provider - Wraps an inner provider, prepending fixed path segments to every lookup.
- Secret
- Wraps a sensitive value so it is never exposed via
fmt::Debugorfmt::Display.
Enums§
- Config
Error - Configuration load / parse failure (Figment + Effect.ts-style provider reads).
Traits§
- Config
Provider - Abstract configuration source (Effect
ConfigProvider). - With
Config Default Config.withDefaultas a method — onlyConfigError::Missingis swapped.
Functions§
- all
- Combine two configs into a tuple (Effect
Config.all/Config.zip). - all3
- Combine three configs into a 3-tuple.
- all_vec
- Load multiple configs and collect results into a
Vec(EffectConfig.allon a slice). - config_
env - Build a minimal
ConfigEnvwrappingprovider. - extract
- Deserialize
Tfrom a preparedFigment. - nest
- Namespace
innerunderprefix(same asConfig::nested). - nested_
path - Build a multi-segment path, e.g.
nested_path("SERVER", &["HOST"])→["SERVER", "HOST"]. - or_
else_ config - Try
primary; fall back tofallbackon a missing key (EffectConfig.orElse). - provide_
config_ provider - Register
provideras theConfigProvidercapability. - provide_
env_ config_ provider - Register an
EnvConfigProviderbuilt with explicit options. - provide_
figment_ config_ provider - Register a
FigmentConfigProviderbuilt fromfigment. - read_
bool - Boolean parsed from
"true"/"false"/"1"/"0"/"yes"/"no". - read_
i64 - Signed 64-bit integer parsed from a string scalar.
- read_
nested_ string nested_paththenread_string.- read_
nested_ string_ list nested_paththenread_string_list.- read_
number - Floating-point number parsed from a string scalar.
- read_
string - Required string.
- read_
string_ list - Sequence of strings split by
ConfigProvider::seq_delim. - read_
string_ opt - Optional string — missing key yields
None. - try_
extract - Same as
extract, explicit name for boolean-heavy call sites. - zip_
with - Combine two configs and merge the results with
f(EffectConfig.zipWith).
Type Aliases§
- Config
Env - Type alias for a minimal capability environment containing only
ConfigProviderService.