Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gothack/layeredconf
Layered Configs for Rust apps
https://github.com/gothack/layeredconf
Last synced: 5 days ago
JSON representation
Layered Configs for Rust apps
- Host: GitHub
- URL: https://github.com/gothack/layeredconf
- Owner: GothAck
- License: mit
- Created: 2021-12-05T02:55:03.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-01-22T22:10:04.000Z (almost 3 years ago)
- Last Synced: 2024-10-12T23:11:16.149Z (about 1 month ago)
- Language: Rust
- Size: 46.9 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Rust](https://github.com/GothAck/layeredconf/actions/workflows/rust.yml/badge.svg)](https://github.com/GothAck/layeredconf/actions/workflows/rust.yml) ![Crates.io](https://img.shields.io/crates/v/layeredconf) ![Crates.io](https://img.shields.io/crates/l/layeredconf) ![docs.rs](https://img.shields.io/docsrs/layeredconf)
# LayeredConf
Yet Another Config Package
## Future
Hopefully this one will be useful to someone. Incoming features:
- More Documentation
- Features## Features
- Generate config Layers loaded from multiple sources: files, strings, command line arguments...
- Uses Clap to auto-generate command line help + usage info
- Most of Clap's derive features are usable
- Can define futher config files to load within config files, or command line options## Quick Example
Add `layeredconf`, `clap`, and `serde` to your `Cargo.toml`
```toml
[dependencies]
layeredconf = "0.2.0"
clap = "3.0.0-beta.5"
serde = { version = "1.0", features = ["derive"] }
```Define your config
```rust,ignore
use layeredconf::{Builder, Format, LayeredConf, Source};
use serde::Deserialize;#[derive(LayeredConf, Deserialize)]
struct Config {
/// Will also load this config file
#[layered(load_config)]
#[clap(long)]
config: Option,/// Required to be set in at least one Layer (config file, command line, etc.)
#[clap(long)]
name: String,/// Optional field
#[clap(long)]
input: Option,/// Defaulted field
#[layered(default)]
#[clap(long)]
number: u32,
}fn main() -> anyhow::Result<()> {
let config: Config = Builder)::new()
.new_layer(Source::OptionalFile {
path: "/etc/my_app/config.yaml",
format: Format::Auto,
})
.new_layer(Source::File {
path: "relative/config.yaml",
format: Format::Auto,
})
.new_layer(Source::Arguments)
.solidify()?;// Use config in your application
}
```