https://github.com/marioortizmanero/structconf
A procedural macro to combine multiple configuration methods at compile time
https://github.com/marioortizmanero/structconf
argument-parser config-file procedural-macro
Last synced: 6 months ago
JSON representation
A procedural macro to combine multiple configuration methods at compile time
- Host: GitHub
- URL: https://github.com/marioortizmanero/structconf
- Owner: marioortizmanero
- License: mit
- Created: 2020-07-06T11:28:36.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-29T00:59:47.000Z (almost 3 years ago)
- Last Synced: 2025-08-02T08:00:52.726Z (6 months ago)
- Topics: argument-parser, config-file, procedural-macro
- Language: Rust
- Size: 2.58 MB
- Stars: 11
- Watchers: 1
- Forks: 2
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
---
StructConf is a small derive macro that allows you to combine argument parsing from [clap](https://github.com/clap-rs/clap) and config file parsing from [rust-ini](https://github.com/zonyitoo/rust-ini) at compile time. It's inspired by the argument parser [structopt](https://github.com/TeXitoi/structopt).
StructConf aims to be relatively small and simple. Here are its current selling points:
* Options available in the config file, argument parser, both, or none.
* Configurable option names.
* Custom types supported.
* Optional fields with `Option`.
* Custom default expressions.
* Insightful error messages.
* Thoroughly tested.
Small example:
```rust
use structconf::{clap, StructConf};
#[derive(Debug, StructConf)]
struct ServerConfig {
#[conf(help = "The public key")]
pub public_key: String,
#[conf(no_file, long = "your-secret", help = "Your secret API key")]
pub secret_key: String,
#[conf(default = "100", help = "timeout in seconds")]
pub timeout: i32,
}
pub fn main() {
let app = clap::App::new("demo");
let conf = ServerConfig::parse(app, "config.ini");
println!("Parsed config: {:#?}", conf);
}
```
For more details on how to use Structconf, read [the docs](https://docs.rs/structconf/) and check out the [examples](examples).