Nonvolatile
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
in some common directory 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. State
instances
are exclusive (i.e., two programs or two instances of the same program cannot
have the same State
open at the same time).
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
.
Check out the documentation here for more detailed information
Example
use State;
use *;
Notes
By default, state for a given name will be stored in
$HOME/.local/rust_nonvolatile/<name>
for Linux and MacOS systems, and
%appdata%\rust_nonvolatile\<name>
for Windows systems. If $HOME or %appdata%
are not defined in the program environment, then nonvolatile will fall back to
/etc
and C:\ProgramData
for Linux/MacOS and Windows respectively.
If your environment is unreliable, or you have a location where you'd rather keep settings
and configuration, the default storage location can be overridden using the
*_from
functions (new_from
instead of new
, load_from
instead of load
,
load_else_create_from
instead of load_else_create
).
Be careful to be consistent with the storage location! If you use a state from one location during one instance of your program, and then use a state from a different location during the next, you will be left with two non-matching states with the same name in different places.
Available State Functions