#conf #config #lazy #simple #lazyf


A quick unified way to grab configuration options from * environment variables * program arguments * config files

2 releases

✓ Uses Rust 2018 edition

0.1.1 Nov 6, 2018
0.1.0 Nov 3, 2018

#51 in Configuration

19 downloads per month
Used in 1 crate

MIT license

540 lines

Changes :

v : 0.1.1

  • Update to 2018.
  • Add help() and add_help method to GetHolder users can flag for --help and get useful info
  • Add s_req() and t_req(), require methods to grabber,
  • Add help() method to Grabber, so devs can describe what flags do
  • Add localize() method to Getable, and Grabber and GetHolder, so that devs can take locations relative to config file path.


The Primary purpose of this module is to provide a super quick way of accessing and prioritizing the three main configuration options:

  • Arguments as Flags
  • Environment Variables
  • Configuration Files

For configuration files I use the lazyf format, which is straight forward to use:

For example, the contents of "test_data/powers.lz":




The structure is only 2 layers deep, and uses any whitespace to indicate that this row is a child or the previous untabbed row.

Intended Use

The intended use of the program is as follows Assuming the previous file is in one of the supplied locations.

use lazy_conf::config;

// note: this has to be "mut" so help messages can be added
// note: this will load the "test_data/powers" file described above
let mut cfg =
                //only fails if -c was provided, but badly formed

// Use grab builder to get the info out.
// note: The help method makes a uses all of the previous cf,fg and env 
//  calls to build a useful message to the user.
let spower = cfg.grab()
                .help("What power") 


// You can search multiple elements of the same kind.
// If the first is not available the second will be chosen:
let home = cfg.grab()


// s() closes returning an Option<String>, 
// t() closes returning a Result<T> where T:FromStr

let age = cfg.grab().cf("Superman.age").t::<i32>();


// The "help" method, checks for the presence of a "--help" in the
// arguments, if found: it prints the compiled help info.

if cfg.help("A Program to collect Superpowers") {
    // if flag --help existed, cfg prints collated help messages,
    // and returns true

// to see the message we can call 
let hs = cfg.help_string("My Program");
My Program
Config file location flag: \"-c\"
default locations : [\"test_data/powers.lz\", \"{HOME}/.config/myprogram.lz\"]
What power:

Loading Files

let cfg = config("-c",[loc1,loc2,loc3,etc]);

The given flag ("-c") allows the user to supply a different path for the main config file.

myprogram -c localconf.lz

Whether or not this flag is supplied, the program will attempt to load all files.

It is not considered an error even if none are found.

When an lz request is made, it will search them all (preloaded) in order "-c", "loc1" ,"loc2", ...

No runtime deps