Search

Lib.rs

› Configuration
#merge #from-anywhere #lib #env-var #file-source

mofa

the config lib that merges options from anywhere

Owned by Kilerd Chan.

  • Install
  • API reference
  • GitHub repo (kilerd)

3 releases

0.1.2 Jan 29, 2025
0.1.1 Jan 26, 2025
0.1.0 Dec 27, 2024

#1136 in Configuration

Download history 6/week @ 2026-01-19 70/week @ 2026-02-02 8/week @ 2026-02-23

338 downloads per month

MIT license

22KB
464 lines

mofa

the config lib that Merges options from anywhere

GitHub Workflow Status (with branch) Crates.io Crates.io (recent) docs.rs Crates.io

Features

  • hierarchy file supported: file source allow users to load config from multiple files
  • environment variable resolver: mofa can resolve the placeholder like ${APP_KEY_NAME}
  • path variable resolver: mofa can resolve the placeholder like ${parent.sub.key_name}

Installation

$ cargo add mofa

Example

#[derive(Debug, Deserialize)]
struct Config {
    original: String,
    value: String,
}
fn main() {
    let mut loader = ConfigLoader::new();
    loader.add_source(FileSource::new("configuration/application.toml"));
    loader.add_source(FileSource::new("configuration/application_database.toml"));
    loader.add_source(EnvironmentSource::new("APP"));
    loader.enable_environment_variable_processor();
    loader.enable_path_variable_processor();

    let config: Config = loader.construct()?;
}

Contributing

Want to join us? Check out our "Contributing" guide and take a look at some of these issues:

  • Issues labeled "good first issue"
  • Issues labeled "help wanted"

License

This project is licensed under MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT).

Dependencies

~2.7–4MB
~75K SLoC

  • itertools 0.14
  • regex
  • serde
  • toml 0.8
  • dev temp-env
  • dev tempfile
Related: gotcha_macro, gotcha_core, tracing-layer-axiom, latestmap, gotcha, now
See also: gix-blame, gst-plugin-file, wgsl_bindgen, cfgmatic-source, trail-config, cjkfmt, lopdf, env-settings, iprange, scuffle-settings, serde-vars

Lib.rs is an unofficial list of Rust/Cargo crates, created by kornelski. It contains data from multiple sources, including heuristics, and manually curated data. Content of this page is not necessarily endorsed by the authors of the crate. This site is not affiliated with nor endorsed by the Rust Project. If something is missing or incorrect, please file a bug.