#[repr(transparent)]pub struct StrLeaf<T: ?Sized>(pub T);
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, Leaf, StrLeaf, Tree};
#[derive(Tree, strum::AsRefStr, strum::EnumString)]
enum En {
A(Leaf<i32>),
B(Leaf<f32>),
}
#[derive(Tree)]
struct S {
e: StrLeaf<En>,
#[tree(typ="En", defer=*self.e)]
t: (),
}
let mut s = S {
e: StrLeaf(En::A(9.into())),
t: (),
};
json::set(&mut s, "/e", b"\"B\"").unwrap();
json::set(&mut s, "/t/B", b"1.2").unwrap();
assert!(matches!(*s.e, En::B(Leaf(1.2))));
Tuple Fields§
§0: T
Implementations§
source§impl<T> StrLeaf<T>
impl<T> StrLeaf<T>
sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Extract just the inner
Trait Implementations§
source§impl<'de, T> Deserialize<'de> for StrLeaf<T>where
T: Deserialize<'de> + ?Sized,
impl<'de, T> Deserialize<'de> for StrLeaf<T>where
T: Deserialize<'de> + ?Sized,
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl<T: PartialOrd + ?Sized> PartialOrd for StrLeaf<T>
impl<T: PartialOrd + ?Sized> PartialOrd for StrLeaf<T>
source§impl<T> TreeAny for StrLeaf<T>
impl<T> TreeAny for StrLeaf<T>
source§fn ref_any_by_key<K>(&self, keys: K) -> Result<&dyn Any, Traversal>where
K: Keys,
fn ref_any_by_key<K>(&self, keys: K) -> Result<&dyn Any, Traversal>where
K: Keys,
Obtain a reference to a
dyn Any
trait object for a leaf node.source§fn mut_any_by_key<K>(&mut self, keys: K) -> Result<&mut dyn Any, Traversal>where
K: Keys,
fn mut_any_by_key<K>(&mut self, keys: K) -> Result<&mut dyn Any, Traversal>where
K: Keys,
Obtain a mutable reference to a
dyn Any
trait object for a leaf node.source§impl<'de, T: TryFrom<&'de str>> TreeDeserialize<'de> for StrLeaf<T>
impl<'de, T: TryFrom<&'de str>> TreeDeserialize<'de> for StrLeaf<T>
source§fn deserialize_by_key<K, D>(
&mut self,
keys: K,
de: D,
) -> Result<usize, Error<D::Error>>where
K: Keys,
D: Deserializer<'de>,
fn deserialize_by_key<K, D>(
&mut self,
keys: K,
de: D,
) -> Result<usize, Error<D::Error>>where
K: Keys,
D: Deserializer<'de>,
Deserialize a leaf node by its keys. Read more
source§impl<T: ?Sized> TreeKey for StrLeaf<T>
impl<T: ?Sized> TreeKey for StrLeaf<T>
source§impl<T: AsRef<str> + ?Sized> TreeSerialize for StrLeaf<T>
impl<T: AsRef<str> + ?Sized> TreeSerialize for StrLeaf<T>
source§fn serialize_by_key<K, S>(
&self,
keys: K,
ser: S,
) -> Result<usize, Error<S::Error>>where
K: Keys,
S: Serializer,
fn serialize_by_key<K, S>(
&self,
keys: K,
ser: S,
) -> Result<usize, Error<S::Error>>where
K: Keys,
S: Serializer,
Serialize a node by keys. Read more
impl<T: Copy + ?Sized> Copy for StrLeaf<T>
impl<T: Eq + ?Sized> Eq for StrLeaf<T>
impl<T: ?Sized> StructuralPartialEq for StrLeaf<T>
Auto Trait Implementations§
impl<T> Freeze for StrLeaf<T>
impl<T> RefUnwindSafe for StrLeaf<T>where
T: RefUnwindSafe + ?Sized,
impl<T> Send for StrLeaf<T>
impl<T> Sync for StrLeaf<T>
impl<T> Unpin for StrLeaf<T>
impl<T> UnwindSafe for StrLeaf<T>where
T: UnwindSafe + ?Sized,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)