cfg-rs: A Configuration Library for Rust Applications

Overview

cfg-rs: A Configuration Library for Rust Applications

Crates.io Crates.io Documentation dependency status License Actions Status Minimum supported Rust version

Major Features

  • One method to get all config objects, see get.
  • Automatic derive config object, see FromConfig.
  • Support default value for config object by auto deriving, see derived attr.
  • Config value placeholder parsing, e.g. ${config.key}, see placeholder.
  • Random config value, e.g. configuration.get:: ("random.u8") will get random u8 value.
  • Support refreshable value type RefValue, it can be updated when refreshing.
  • Support refresh Configuration.
  • Easy to use, easy to add new config source, easy to organize configuration, see register_source.[^priority]

See the examples for general usage information.

[^priority]: Config order is determined by the order of registering sources, register earlier have higher priority.

Supported File Format

  • Toml: toml, tml
  • Yaml: yaml, yml
  • Json: json
  • Ini: ini

How to Initialize Configuration

  • Use Predefined Source Configuration in One Line
use cfg_rs::*;
let configuration = Configuration::with_predefined().unwrap();
// use configuration.

See init for details.

  • Customize Predefined Source Configuration Builder
use cfg_rs::*;
init_cargo_env!();
let configuration = Configuration::with_predefined_builder()
    .set_cargo_env(init_cargo_env())
    .init()
    .unwrap();
// use configuration.

See init for details.

  • Organize Your Own Sources
use cfg_rs::*;
init_cargo_env!();
let mut configuration = Configuration::new()
    // Layer 0: Register cargo env config source.
    .register_source(init_cargo_env()).unwrap()
    // Layer 1: Register customized config.
    .register_kv("customized_config")
        .set("hello", "world")
        .finish()
        .unwrap();
    // Layer 2: Register random value config.
#[cfg(feature = "rand")]
{
configuration = configuration.register_random().unwrap();
}
    // Layer 3: Register all env variables `CFG_*`.
configuration = configuration.register_prefix_env("CFG").unwrap()
    // Layer 4: Register yaml file(Need feature yaml).
    .register_file("/conf/app.yaml", true).unwrap();

#[cfg(feature = "toml")]
{
    let toml = inline_source!("../app.toml").unwrap();
    configuration = configuration.register_source(toml).unwrap();
}

// use configuration.

See register_kv, register_file, register_random, register_prefix_env for details.

Comments
  • Update Rust crate env_logger to 0.10

    Update Rust crate env_logger to 0.10

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | env_logger | dev-dependencies | minor | 0.9 -> 0.10 |


    Release Notes

    env-logger-rs/env_logger

    v0.10.0

    Compare Source

    MSRV changed to 1.60 to hide optional dependencies

    Fixes
    • Resolved soundness issue by switching from atty to is-terminal
    Breaking Changes

    To open room for changing dependencies:

    • Renamed termcolor feature to color
    • Renamed atty feature to auto-color

    v0.9.3

    Compare Source

    • Fix a regression from v0.9.2 where env_logger would fail to compile with the termcolor feature turned off.

    v0.9.2

    Compare Source

    • Fix and un-deprecate Target::Pipe, which was basically not working at all before and deprecated in 0.9.1.

    v0.9.1

    Compare Source


    Configuration

    📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
  • Update Rust crate regex to ^1.7.0

    Update Rust crate regex to ^1.7.0

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | regex | dev-dependencies | minor | ^1.6.0 -> ^1.7.0 |


    Release Notes

    rust-lang/regex

    v1.7.0

    Compare Source

    ================== This release principally includes an upgrade to Unicode 15.

    New features:


    Configuration

    📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
  • Update Rust crate criterion to 0.4

    Update Rust crate criterion to 0.4

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | criterion (source) | dev-dependencies | minor | 0.3 -> 0.4 |


    Release Notes

    bheisler/criterion.rs

    v0.4.0

    Compare Source

    Removed
    • The Criterion::can_plot function has been removed.
    • The Criterion::bench_function_over_inputs function has been removed.
    • The Criterion::bench_functions function has been removed.
    • The Criterion::bench function has been removed.
    Changed
    • HTML report hidden behind non-default feature flag: 'html_reports'
    • Standalone support (ie without cargo-criterion) feature flag: 'cargo_bench_support'
    • MSRV bumped to 1.57
    • rayon and plotters are optional (and default) dependencies.
    • Status messages ('warming up', 'analyzing', etc) are printed to stderr, benchmark results are printed to stdout.
    • Accept subsecond durations for --warm-up-time, --measurement-time and --profile-time.
    • Replaced serde_cbor with ciborium because the former is no longer maintained.
    • Upgrade clap to v3 and regex to v1.5.
    Added
    • A --discard-baseline flag for discarding rather than saving benchmark results.
    • Formal support for benchmarking code compiled to web-assembly.
    • A --quiet flag for printing just a single line per benchmark.
    • A Throughput::BytesDecimal option for measuring throughput in bytes but printing them using decimal units like kilobytes instead of binary units like kibibytes.
    Fixed
    • When using bench_with_input, the input parameter will now be passed through black_box before passing it to the benchmark.

    v0.3.6

    Compare Source

    Changed
    • MSRV bumped to 1.49
    • Symbol for microseconds changed from ASCII 'us' to unicode 'µs'
    • Documentation fixes
    • Clippy fixes

    v0.3.5

    Compare Source

    Fixed
    • Corrected Criterion.toml in the book.
    • Corrected configuration typo in the book.
    Changed
    • Bump plotters dependency to always include a bug-fix.
    • MSRV bumped to 1.46.

    v0.3.4

    Compare Source

    Added
    • Added support for benchmarking async functions
    • Added with_output_color for enabling or disabling CLI output coloring programmatically.
    Fixed
    • Criterion.rs will now give a clear error message in case of benchmarks that take zero time.
    • Added some extra code to ensure that every sample has at least one iteration.
    • Added a notice to the --help output regarding "unrecognized option" errors.
    • Increased opacity on violin charts.
    • Fixed violin chart X axis not starting at zero in the plotters backend.
    • Criterion.rs will now automatically detect the right output directory.
    Deprecated
    • Criterion::can_plot is no longer useful and is deprecated pending deletion in 0.4.0.
    • Benchmark and ParameterizedBenchmark were already hidden from documentation, but are now formally deprecated pending deletion in 0.4.0. Callers should use BenchmarkGroup instead.
    • Criterion::bench_function_over_inputs, Criterion::bench_functions, and Criterion::bench were already hidden from documentation, but are now formally deprecated pending deletion in 0.4.0. Callers should use BenchmarkGroup instead.
    • Three new optional features have been added; "html_reports", "csv_output" and "cargo_bench_support". These features currently do nothing except disable a warning message at runtime, but in version 0.4.0 they will be used to enable HTML report generation, CSV file generation, and the ability to run in cargo-bench (as opposed to cargo-criterion). "cargo_bench_support" is enabled by default, but "html_reports" and "csv_output" are not. If you use Criterion.rs' HTML reports, it is recommended to switch to cargo-criterion. If you use CSV output, it is recommended to switch to cargo-criterion and use the --message-format=json option for machine-readable output instead. A warning message will be printed at the start of benchmark runs which do not have "html_reports" or "cargo_bench_support" enabled, but because CSV output is not widely used it has no warning.

    v0.3.3

    Compare Source

    Added
    • Added CRITERION_HOME environment variable to set the directory for Criterion to store its results and charts in.
    • Added support for [cargo-criterion]. The long-term goal here is to remove code from Criterion-rs itself to improve compile times, as well as to add features to cargo-criterion that are difficult to implement in Criterion-rs.
    • Add sampling mode option for benchmarks. This allows the user to change how Criterion.rs chooses the iteration counts in each sample. By default, nothing will change for most benchmarks, but very slow benchmarks will now run fewer iterations to fit in the desired number of samples. This affects the statistics and plots generated.
    Changed
    • The serialization format for some of the files has changed. This may cause your first benchmark run after updating to produce errors, but they're harmless and will go away after running the benchmarks once.
    Fixed
    • Fixed a bug where the current measurement was not shown on the relative regression plot.
    • Fixed rare panic in the plotters backend.
    • Panic with a clear error message (rather than panicking messily later on) when the user sets the group or function name to the empty string.
    • Escape single quotes in benchmark names when generating Gnuplot scripts.

    v0.3.2

    Compare Source

    Added
    • Added ?Sized bound to benchmark parameter types, which allows dynamically sized types like &str and &[T] to be used as benchmark parameters.
    • Added the --output-format <format> command-line option. If --output-format bencher is passed, Criterion.rs will print its measurements in a format similar to that used by the bencher crate or unstable libtest benchmarks, and using similar statistical measurements as well. Though this provides less information than the default format, it may be useful for supporting tools which parse this output format.
    • Added --nocapture argument. This argument does nothing, but prevents Criterion.rs from exiting when running tests or benchmarks and allowing stdout output from other tests.
    Fixed
    • Fixed panic when environment variables contains non-UTF8 characters.
    • Fixed panic when CRITERION_DEBUG or CRITERION_TARGET_DIR environment variables contain non-UTF8 characters.

    v0.3.1

    Compare Source

    Added
    • Added new plotting backend using the plotters crate. Implementation generously provided by Hao Hou, author of the plotters crate.
    • Added --plotting-backend command-line option to select the plotting backend. The existing gnuplot backend will be used by default when available, and the plotters backend will be used when gnuplot is not available or when requested.
    • Added Criterion::plotting_backend() function to configure the plotting backend in code.
    • Added --load-baseline command-line option to load a baseline for comparison rather than measuring the current code
    • Benchmark filters can now be regular expressions.
    Fixed
    • Fixed fibonacci functions.
    • Fixed #[criterion] benchmarks ignoring the command-line options.
    • Fixed incorrect scaling of the violin plots.
    • Don't print the recommended sample count if it's the same as the configured sample count.
    • Fix potential panic when nresamples is set too low. Also added a warning against setting nresamples too low.
    • Fixed issue where a slow outer closure would cause Criterion.rs to calculate the wrong estimated time and number of iterations in the warm-up phase.

    Configuration

    📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, click this checkbox.

    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
  • Update actions/checkout action to v3

    Update actions/checkout action to v3

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | actions/checkout | action | major | v2 -> v3 |


    Release Notes

    actions/checkout

    v3

    Compare Source


    Configuration

    📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, click this checkbox.

    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
  • Update Rust crate regex to ^1.6.0

    Update Rust crate regex to ^1.6.0

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | regex | dev-dependencies | minor | ^1.5.5 -> ^1.6.0 |


    Release Notes

    rust-lang/regex

    v1.6.0

    Compare Source

    ================== This release principally includes an upgrade to Unicode 14.

    New features:

    Bug fixes:

    v1.5.6

    Compare Source

    ================== This release includes a few bug fixes, including a bug that produced incorrect matches when a non-greedy ? operator was used.

    • BUG #​680: Fixes a bug where [[:alnum:][:^ascii:]] dropped [:alnum:] from the class.
    • BUG #​859: Fixes a bug where Hir::is_match_empty returned false for \b.
    • BUG #​862: Fixes a bug where 'ab??' matches 'ab' instead of 'a' in 'ab'.

    Configuration

    📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, click this checkbox.

    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
  • Configure Renovate

    Configure Renovate

    Mend Renovate

    Welcome to Renovate! This is an onboarding PR to help you understand and configure settings before regular Pull Requests begin.

    🚦 To activate Renovate, merge this Pull Request. To disable Renovate, simply close this Pull Request unmerged.


    Detected Package Files

    • Cargo.toml (cargo)
    • cfg-derive/Cargo.toml (cargo)
    • .github/workflows/rust.yaml (github-actions)

    Configuration Summary

    Based on the default config's presets, Renovate will:

    • Start dependency updates only once this onboarding PR is merged
    • Enable Renovate Dependency Dashboard creation.
    • If Renovate detects semantic commits, it will use semantic commit type fix for dependencies and chore for all others.
    • Ignore node_modules, bower_components, vendor and various test/tests directories.
    • Autodetect whether to pin dependencies or maintain ranges.
    • Rate limit PR creation to a maximum of two per hour.
    • Limit to maximum 10 open PRs at any time.
    • Group known monorepo packages together.
    • Use curated list of recommended non-monorepo package groupings.
    • A collection of workarounds for known problems with packages.

    🔡 Would you like to change the way Renovate is upgrading your dependencies? Simply edit the renovate.json in this branch with your custom config and the list of Pull Requests in the "What to Expect" section below will be updated the next time Renovate runs.


    What to Expect

    With your current configuration, Renovate will create 2 Pull Requests:

    Update Rust crate regex to ^1.6.0
    • Schedule: ["at any time"]
    • Branch name: renovate/regex-1.x
    • Merge into: main
    • Upgrade regex to ^1.6.0
    Update actions/checkout action to v3
    • Schedule: ["at any time"]
    • Branch name: renovate/actions-checkout-3.x
    • Merge into: main
    • Upgrade actions/checkout to v3

    ❓ Got questions? Check out Renovate's Docs, particularly the Getting Started section. If you need any further assistance then you can also request help here.


    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
  • Update Rust crate regex to ^1.7.1

    Update Rust crate regex to ^1.7.1

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | regex | dev-dependencies | patch | ^1.7.0 -> ^1.7.1 |


    Release Notes

    rust-lang/regex

    v1.7.1

    Compare Source

    ================== This release was done principally to try and fix the doc.rs rendering for the regex crate.

    Performance improvements:

    • PERF #​930: Optimize replacen. This also applies to replace, but not replace_all.

    Bug fixes:

    • BUG #​945: Maybe fix rustdoc rendering by just bumping a new release?

    Configuration

    📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
  • Dependency Dashboard

    Dependency Dashboard

    This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

    Open

    These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

    Detected dependencies

    cargo
    Cargo.toml
    • json ^0.12
    • log ^0.4
    • rand_chacha ^0.3
    • rand_core ^0.6
    • rust-ini ^0.18
    • toml ^0.5
    • yaml-rust ^0.4.5
    • criterion 0.4
    • regex ^1.7.0
    • env_logger 0.10
    • log 0.4
    • quickcheck 1
    • quickcheck_macros 1
    cfg-derive/Cargo.toml
    • quote 1
    • syn 1
    github-actions
    .github/workflows/rust.yaml
    • actions/checkout v3
    • actions-rs/toolchain v1

    • [ ] Check this box to trigger a request for Renovate to run again on this repository
    opened by renovate[bot] 0
Owner
Daniel YU
GPG: 0x120152685ACE7222
Daniel YU
A systemd-boot configuration and boot entry configuration parser library

A systemd-boot configuration and boot entry configuration parser library

Kaiyang Wu 2 May 22, 2022
Kusion Configuration Language (KCL) is an open source configuration language mainly used in Kusion Stack

Kusion Configuration Language (KCL) is an open source configuration language mainly used in Kusion Stack. KCL is a statically typed language for configuration and policy scenarios, based on concepts such as declarative and Object-Oriented Programming (OOP) paradigms.

KusionStack 264 Dec 30, 2022
Just-config is a configuration library for rust

Config Library for Rust Just-config is a configuration library for rust. It strives for the old Unix mantra "Do one thing and to it well".

FlashSystems 7 Apr 15, 2022
A Rust library for processing application configuration easily

Configure me A Rust library for processing application configuration easily About This crate aims to help with reading configuration of application fr

Martin Habovštiak 48 Dec 18, 2022
Zap - A simple cross-platform configuration management and orchestration tool

Zap - A simple cross-platform orchestration and configuration management tool. The main goal for Zap is to a simple mechanism for managing groups of com

R. Tyler Croy 50 Oct 29, 2022
Uclicious is a flexible reduced boilerplate configuration framework.

Uclicious What is Uclicious Usage Raw API Derive-driven Validators Type Mapping Supported attributes (#[ucl(..)]) Structure level Field level Addition

Andrey Cherkashin 14 Aug 12, 2022
🌽 A simple and pain-free configuration language.

?? Corn A simple and pain-free configuration language. Corn has been designed using inspiration from JSON and Nix to produce a language that's easy an

Jake Stanger 3 Nov 28, 2022
hosts file parsing, modification library, and some derivatives.

hosts-rs hosts: Hosts file parsing, modification library resolve-github: Use Cloudflare DoH to resolve GitHub domains and generate hosts files github-

zu1k 33 Jul 4, 2022
This repository is an experimental WebAssembly build of the [ymfm] Yamaha FM sound cores library.

This repository is an experimental WebAssembly build of the [ymfm] Yamaha FM sound cores library.

hiromasa 36 Dec 25, 2022
Build a config structure from environment variables in Rust without boilerplate

Yasec Yet another stupid environment config (YASEC) creates settings from environment variables. (Envconig-rs fork) Features Nested configuration stru

null 4 Dec 28, 2021
Your next config manager, written in rust

confy Your next config manager, written in rust Based on uncomfyhalomacro/hmph but written for .ini files instead of json :) Getting started Take a lo

Krishna Ramasimha 2 Nov 3, 2021
An easy to configure wrapper for Rust's clippy

An easy to configure wrapper for Rust's clippy

Eric Seppanen 46 Dec 19, 2022
Easy c̵̰͠r̵̛̠ö̴̪s̶̩̒s̵̭̀-t̶̲͝h̶̯̚r̵̺͐e̷̖̽ḁ̴̍d̶̖̔ ȓ̵͙ė̶͎ḟ̴͙e̸̖͛r̶̖͗ë̶̱́ṉ̵̒ĉ̷̥e̷͚̍ s̷̹͌h̷̲̉a̵̭͋r̷̫̊ḭ̵̊n̷̬͂g̵̦̃ f̶̻̊ơ̵̜ṟ̸̈́ R̵̞̋ù̵̺s̷̖̅ţ̸͗!̸̼͋

Rust S̵̓i̸̓n̵̉ I̴n̴f̶e̸r̵n̷a̴l mutability! Howdy, friendly Rust developer! Ever had a value get m̵̯̅ð̶͊v̴̮̾ê̴̼͘d away right under your nose just when

null 294 Dec 23, 2022
⚙️ Layered configuration system for Rust applications (with strong support for 12-factor applications).

config-rs Layered configuration system for Rust applications (with strong support for 12-factor applications). Set defaults Set explicit values (to pr

Ryan Leckey 1.8k Jan 9, 2023
A systemd-boot configuration and boot entry configuration parser library

A systemd-boot configuration and boot entry configuration parser library

Kaiyang Wu 2 May 22, 2022
A rust layered configuration loader with zero-boilerplate configuration management.

salak A layered configuration loader with zero-boilerplate configuration management. About Features Placeholder Key Convension Cargo Features Default

Daniel YU 28 Sep 20, 2022
Kusion Configuration Language (KCL) is an open source configuration language mainly used in Kusion Stack

Kusion Configuration Language (KCL) is an open source configuration language mainly used in Kusion Stack. KCL is a statically typed language for configuration and policy scenarios, based on concepts such as declarative and Object-Oriented Programming (OOP) paradigms.

KusionStack 264 Dec 30, 2022
wireguard tool to manage / generate configuration. Maintain one yaml configuration file to quickly build wireguard network.

wgx wireguard tool to manage / generate configuration. Maintain one yaml configuration file to quickly build wireguard network. Usage wgx --h USAGE:

yinheli 6 Nov 3, 2022
Decentralized Autonomous Applications (DAAs). Building the Future with Self-Managing Applications.

Decentralized Autonomous Applications (DAAs) Building the Future with Self-Managing Applications. ?? Straw Man Code Outline ?? Reddit Group ?? Twitter

rUv 100 Apr 15, 2023
Just-config is a configuration library for rust

Config Library for Rust Just-config is a configuration library for rust. It strives for the old Unix mantra "Do one thing and to it well".

FlashSystems 7 Apr 15, 2022