#config #configuration #settings #clap #rust-ini

structconf

Combine clap and rust-ini into a single procedural macro

8 unstable releases (3 breaking)

new 0.4.0 Sep 14, 2020
0.3.2 Jul 13, 2020
0.2.0 Jul 12, 2020
0.1.3 Jul 10, 2020

#50 in Configuration

Download history 1/week @ 2020-07-03 101/week @ 2020-07-10 14/week @ 2020-07-17 14/week @ 2020-07-24 8/week @ 2020-07-31 7/week @ 2020-08-07 20/week @ 2020-08-14 102/week @ 2020-08-21 7/week @ 2020-08-28 21/week @ 2020-09-04 22/week @ 2020-09-11

98 downloads per month

MIT license

20KB
99 lines

StructConf

Combine argument parsing with a config file at compile time.

Build Status docs.rs version


StructConf is a small derive macro that allows you to combine argument parsing from clap and config file parsing from rust-ini at compile time. It's inspired by the argument parser structopt, and developed to be used in Vidify.

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:

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 and check out the examples.

Dependencies

~3MB
~58K SLoC