Configory
Configory is a batteries included configuration management library which handles all the gory details of supporting configuration files while also supporting IPC access and overrides.
Example
To get a configuration which is backed by a file that is automatically
reloaded on change, you just need to create a config with Manager::new
:
use Manager;
let manager = new.unwrap;
manager.set;
assert_eq!;
This will also automatically spawn an IPC server which allows configuration
file access and modification through a socket file. If you want to disable
this, you can use Manager::with_options
.
The event handler passed to Manager::new
or Manager::with_options
can be used to handle configuration changes, custom IPC messages, and
errors.
use Arc;
use ;
use ;
/// Event handler with a configuration change counter.
// Register our event handler, which increments a counter on change.
let changes = new;
let event_handler = MyEventHandler ;
let manager = new.unwrap;
// Update the config through direct access and IPC.
manager.set;
manager.ipc.unwrap.set;
// Verify the config is correct and was changed once through IPC.
assert_eq!;
assert_eq!;
assert_eq!;
IPC client
The client side of the IPC interface is constructed from the socket path,
which can be acquired using Manager::ipc
and Ipc::socket_path
.
use Manager;
use Ipc;
// This would typically happen in a separate process.
let manager = new.unwrap;
let socket_path = manager.ipc.unwrap.socket_path;
// Set and retrieve a configuration value through the socket.
let ipc = client;
ipc.set.unwrap;
let value = ipc..unwrap;
assert_eq!;
Struct Deserialization
If you prefer accessing configuration values through a struct rather than
using the dynamic syntax of Config::get
, you can deserialize the
toplevel value into your struct:
use Manager;
use Deserialize;
let manager = new.unwrap;
// Without configuration file, the default will be empty.
let my_config = manager.;
assert_eq!;
// Once changed wit the path syntax, the field will be uptaded.
manager.set;
let my_config = manager..unwrap.unwrap;
assert_eq!;