#settings #configuration #storage #store #local

nonvolatile

A package providing the ability to store configuration data out of the way

8 releases (5 breaking)

✓ Uses Rust 2018 edition

0.6.1 Oct 3, 2019
0.6.0 Oct 2, 2019
0.5.1 Sep 5, 2019
0.4.0 Aug 29, 2019
0.1.0 Aug 14, 2019

#43 in Configuration

Download history 4/week @ 2019-08-08 26/week @ 2019-08-15 69/week @ 2019-08-22 35/week @ 2019-08-29 28/week @ 2019-09-05 30/week @ 2019-09-12 86/week @ 2019-09-19 24/week @ 2019-09-26

106 downloads per month

MIT license

16KB
397 lines

Nonvolatile   Latest Version

Nonvolatile is a library for storing persistent settings and configuration data out of the way.

Nonvolatile state is created by instantiating a State instance with a name, usually the name of the program creating it. Any set values are written to disk either in ~/.local/.../[name] or in %appdata%/.../[name], depending on the platform being used. Values persist until they are overwritten, and can be accessed by any program that loads the state with that name.

Most of the builtin types, and any type that implements serde::Serialize/Deserialize may be passed into and read from State::set and State::get.

Example

use nonvolatile::State;
use generic_error::*;

fn main() -> Result<()> {
	
	//create a new state instance with the name "foo"
	let mut state = State::load_else_create("foo")?;
	//set a variable in foo
	state.set("var", String::from("some value"))?;
	
	//destroy the state variable
	drop(state);
	
	//create a new state instance
	let state = State::load_else_create("foo")?;
	//retrieve the previously set variable.
	println!("foo: {}", state.get::<String>("var").unwrap());  //"some value"	
	Ok(())
}

Dependencies

~3.5MB
~72K SLoC