Module str_leaf

Source
Expand description

TryFrom<&str>/AsRef<str> leaf

This wraps TryFrom<&str> and AsRef<str> into a Tree* leaf. TreeAny is implemented but denied access at runtime. It is especially useful to support enum variant switching using strum. Inner enum variant field access can be implemented using defer.

use miniconf::{json_core::set, str_leaf, Tree};
#[derive(Tree, strum::AsRefStr, strum::EnumString)]
enum En {
    A(i32),
    B(f32),
}
#[derive(Tree)]
struct S {
    #[tree(rename="t", with=str_leaf, defer=self.e, typ="En")]
    _t: (),
    e: En,
}
let mut s = S {
    _t: (),
    e: En::A(9),
};
set(&mut s, "/t", b"\"B\"").unwrap();
set(&mut s, "/e/B", b"1.2").unwrap();
assert!(matches!(s.e, En::B(1.2)));

Constants§

SCHEMA
TreeSchema::SCHEMA

Functions§

deserialize_by_key
TreeDeserialize::deserialize_by_key()
mut_any_by_key
TreeAny::mut_any_by_key()
probe_by_key
TreeDeserialize::probe_by_key()
ref_any_by_key
TreeAny::ref_any_by_key()
serialize_by_key
TreeSerialize::serialize_by_key()