Skip to main content

Crate id_effect_config

Crate id_effect_config 

Source
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 Figment builders.

Structs§

Config
A lazy, composable configuration descriptor (Effect.ts Config<T>).
ConfigProviderService
Injectable wrapper around an Arc<dyn ConfigProvider>.
EnvConfigProvider
Reads from std::env using flattened keys (SERVER_PORT for path ["SERVER","PORT"] with default delim).
EnvConfigProviderLive
std::env ConfigProvider with default ProviderOptions.
FigmentConfigProvider
Adapts a merged Figment as a provider (paths joined with ., matching Figment key paths).
FigmentLayer
Deserializes T from a shared Figment on each build.
MapConfigProvider
In-memory map for tests or static overrides (ConfigProvider.fromMap).
OrElseConfigProvider
Try primary first; if it returns None, use fallback (Effect-style provider composition).
ProviderOptions
Options aligned with Effect ConfigProvider.fromEnv (pathDelim, seqDelim).
ScopedConfigProvider
Wraps an inner provider, prepending fixed path segments to every lookup.
Secret
Wraps a sensitive value so it is never exposed via fmt::Debug or fmt::Display.

Enums§

ConfigError
Configuration load / parse failure (Figment + Effect.ts-style provider reads).

Traits§

ConfigProvider
Abstract configuration source (Effect ConfigProvider).
WithConfigDefault
Config.withDefault as a method — only ConfigError::Missing is 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 (Effect Config.all on a slice).
config_env
Build a minimal ConfigEnv wrapping provider.
extract
Deserialize T from a prepared Figment.
nest
Namespace inner under prefix (same as Config::nested).
nested_path
Build a multi-segment path, e.g. nested_path("SERVER", &["HOST"])["SERVER", "HOST"].
or_else_config
Try primary; fall back to fallback on a missing key (Effect Config.orElse).
provide_config_provider
Register provider as the ConfigProvider capability.
provide_env_config_provider
Register an EnvConfigProvider built with explicit options.
provide_figment_config_provider
Register a FigmentConfigProvider built from figment.
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_path then read_string.
read_nested_string_list
nested_path then read_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 (Effect Config.zipWith).

Type Aliases§

ConfigEnv
Type alias for a minimal capability environment containing only ConfigProviderService.