Miniconf
Miniconf enables lightweight (no_std) partial serialization (retrieval) and deserialization
(updates, modification) within a tree by key. The tree is backed by
structs/arrays/Options of serializable types.
Miniconf can be used as a very simple and flexible backend for run-time settings management in embedded devices
over any transport. It was originally designed to work with JSON (serde_json_core)
payloads over MQTT (minimq) and provides a comlete MQTT settings management
client and a Python reference implementation to ineract with it.
Miniconf is completely generic over the serde::Serializer/serde::Deserializer backend and the path hierarchy separator.
Example
use ;
use ;
let mut settings = default;
let mut buf = ;
// Atomic updates by field name
settings.set_json?;
assert_eq!;
settings.set_json?;
settings.set_json?;
settings.set_json?;
settings.set_json?;
settings.set_json?;
// Deep access by field name in a struct
settings.set_json?;
// ... or by index in an array
settings.set_json?;
// ... or by index and then struct field name
settings.set_json?;
// If a deferred Option is `None` it is hidden at runtime and can't be accessed
settings.option_defer = None;
assert_eq!;
settings.option_defer = Some;
settings.set_json?;
settings.option_miniconf = Some.into;
settings.set_json?;
settings.array_option_miniconf = Some.into;
settings.set_json?;
// Serializing elements by path
let len = settings.get_json?;
assert_eq!;
// Iterating over all paths
for path in
# Ok::
MQTT
There is an MQTT-based client that implements settings management over the MQTT protocol with JSON payloads. A Python reference library is provided that interfaces with it.
# Discover the complete unique prefix of an application listening to messages
# under the topic `quartiq/application/12345` and set its `foo` setting to `true`.
Derive macro
For structs Miniconf offers a [macro@Miniconf] derive macro.
The macro implements the [Miniconf] trait that exposes access to serialized field values through their path.
All types supported by either [serde] (and the serde::Serializer/serde::Deserializer backend) or Miniconf
can be used as fields.
Structs, arrays, and Options can then be cascaded to construct more complex trees.
When using the derive macro, the behavior and tree recursion depth can be configured for each
struct field using the #[miniconf(defer(Y))] attribute.
See also the [Miniconf] trait documentation for details.
Keys and paths
Lookup into the tree is done using an iterator over [Key] items. usize indices or &str names are supported.
Path iteration is supported with arbitrary separator between names.
Formats
Miniconf is generic over the serde backend/payload format and the path hierarchy separator.
Currently support for / as the path hierarchy separator and JSON (serde_json_core) is implemented
through the [JsonCoreSlash] super trait.
Transport
Miniconf is designed to be protocol-agnostic. Any means that can receive key-value input from some external source can be used to modify values by path.
Limitations
Deferred/deep/non-atomic access to inner elements of some types is not yet supported, e.g. enums
other than [core::option::Option]. These are still however usable in their atomic serde form as leaves.
Features
mqtt-clientEnable the MQTT client feature. See the example in [MqttClient].json-coreEnable the [JsonCoreSlash] implementation of serializing from and into json slices (usingserde_json_core).
The mqtt-client and json-core features are enabled by default.