miniconf

Module json

source
Expand description

TreeSerialize/TreeDeserialize with “JSON and /”.

Access items with '/' as path separator and JSON (from serde-json-core) as serialization/deserialization payload format.

Paths used here are reciprocal to TreeKey::lookup::<Path<_, '/'>, _>(...)/ TreeKey::nodes::<Path<_, '/'>>().

use miniconf::{json, Leaf, Tree};
#[derive(Tree, Default)]
struct S {
    foo: Leaf<u32>,
    bar: [Leaf<u16>; 2],
};
let mut s = S::default();
json::set(&mut s, "/bar/1", b"9").unwrap();
assert_eq!(*s.bar[1], 9);
let mut buf = [0u8; 10];
let len = json::get(&mut s, "/bar/1", &mut buf[..]).unwrap();
assert_eq!(&buf[..len], b"9");

Functions§

  • Retrieve a serialized value by path.
  • Retrieve a serialized value by key.
  • Update a node by path.
  • Update a node by key.