Expand description

A simple configuration reader.

This crate tries to make it easy to add a configuration file to your project. It’s not the fastest out there, and it does make allocations, but I’ve tried my best to make it easy to use and the docs easy to read.

The Format

It’s a kind of tree, key-value thing. Lines are key-value pairs, the value starting at the first space after the indent. You can add a child to a value by indenting it with spaces or tabs. Indent the same amount to add another child to that same value. Indent more than you did initially to add a grandchild. Don’t mix spaces and tabs. Like this!

Root this is the root
	Child I'm a child!
	Child You can have multiple children with the same keys!
		Grandchild I'm a grandchild!

Example

use confindent::Confindent;

fn main() {
	let conf: Confindent = "Pet Dog\n\tName Brady\n\tAge 10".parse().unwrap();
	let pet = conf.child("Pet").unwrap();
	let name = pet.child_value("Name").unwrap();
	let age: usize = pet.child_parse("Age").unwrap();

	let word = match pet.value() {
		Some("Dog") => "pupper",
		Some("Cat") => "kitty",
		_ => panic!(),
	};

	if age > 9 {
		println!("{}! {} is an old {}.", age, name, word);
	} else {
		println!("Only {}! {} is a good, young {}.", age, name, word);
	}
}

Structs

A parsed configuration file. This struct holds the values with no indentation.

Our main error type.

A parsed line of a configuration file.

Enums

What kind of error happened? Oh, ParseErrorKind of error.

Error returned when parsing a value fails