Crates.io | me0e |
lib.rs | me0e |
version | 0.2.5 |
source | src |
created_at | 2024-07-23 22:21:06.176022 |
updated_at | 2024-07-23 22:21:06.176022 |
description | Metre, the configuration loader for Rust |
homepage | |
repository | https://github.com/ramiroaisen/metre |
max_upload_size | |
id | 1313323 |
size | 59,017 |
#[derive(Config)]
metre is a configuration loader for Rust that allows you to load configurations from a variety of formats such as toml, json, jsonc and yaml
It also supports a variety of sources such as program defaults, env variables, files, and urls.
use metre::{Config, ConfigLoader, Format};
#[derive(Config)]
struct MyConfig {
#[config(default = 8000)]
port: u16,
foo: String
}
let mut loader = ConfigLoader::<MyConfig>::new();
loader.defaults()?;
loader.file("config.json", Format::Json)?;
loader.env()?;
// config have the type MyConfig here
let config = loader.finish()?;
metre focus is to provide a declarative and type-safe way to load configurations in Rust.
metre works by defining a struct that implements the Config
trait, usually via the #[derive(Config)]
macro.
Under the hood metre creates deep partial version of the struct to accumulate the configuration from different sources.
Once all the configuration is accumulated, you can access the final configuration as the defined struct. If the sum of all sources does not comply with the required properties, metre will return an error.
cargo add metre