Skip to main content

ralph_workflow/
config_loading.rs

1//! Configuration loading composition functions.
2//!
3//! This module provides composition functions that wire pure domain
4//! functions to effectful capabilities.
5
6/// Load a configuration value from the environment with a default.
7pub fn load_config_with_default<T>(
8    get_env_var: impl Fn(&str) -> Option<String>,
9    key: &str,
10    default: T,
11) -> T
12where
13    T: std::str::FromStr,
14    <T as std::str::FromStr>::Err: std::fmt::Debug,
15{
16    get_env_var(key)
17        .and_then(|v| v.parse().ok())
18        .unwrap_or(default)
19}