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)));