Struct miniconf::StrLeaf

source ·
#[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>

source

pub fn into_inner(self) -> T

Extract just the inner

Trait Implementations§

source§

impl<T: Clone + ?Sized> Clone for StrLeaf<T>

source§

fn clone(&self) -> StrLeaf<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug + ?Sized> Debug for StrLeaf<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: Default + ?Sized> Default for StrLeaf<T>

source§

fn default() -> StrLeaf<T>

Returns the “default value” for a type. Read more
source§

impl<T: ?Sized> Deref for StrLeaf<T>

source§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<T: ?Sized> DerefMut for StrLeaf<T>

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

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>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<T> From<T> for StrLeaf<T>

source§

fn from(value: T) -> Self

Converts to this type from the input type.
source§

impl<T: Hash + ?Sized> Hash for StrLeaf<T>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
source§

impl<T: Ord + ?Sized> Ord for StrLeaf<T>

source§

fn cmp(&self, other: &StrLeaf<T>) -> Ordering

This method returns an Ordering between self and other. Read more
source§

impl<T: PartialEq + ?Sized> PartialEq for StrLeaf<T>

source§

fn eq(&self, other: &StrLeaf<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: PartialOrd + ?Sized> PartialOrd for StrLeaf<T>

source§

fn partial_cmp(&self, other: &StrLeaf<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T> Serialize for StrLeaf<T>
where T: Serialize + ?Sized,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<T> TreeAny for StrLeaf<T>

source§

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,

Obtain a mutable reference to a dyn Any trait object for a leaf node.
source§

fn ref_by_key<T: Any, K: IntoKeys>(&self, keys: K) -> Result<&T, Traversal>

Obtain a reference to a leaf of known type by key.
source§

fn mut_by_key<T: Any, K: IntoKeys>( &mut self, keys: K, ) -> Result<&mut T, Traversal>

Obtain a mutable reference to a leaf of known type by key.
source§

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>,

Deserialize a leaf node by its keys. Read more
source§

impl<T: ?Sized> TreeKey for StrLeaf<T>

source§

fn traverse_all<W: Walk>() -> Result<W, W::Error>

Walk metadata about all paths. Read more
source§

fn traverse_by_key<K, F, E>(keys: K, _func: F) -> Result<usize, Error<E>>
where K: Keys, F: FnMut(usize, Option<&'static str>, NonZero<usize>) -> Result<(), E>,

Traverse from the root to a leaf and call a function for each node. Read more
source§

fn transcode<N, K>(keys: K) -> Result<(N, Node), Traversal>
where K: IntoKeys, N: Transcode + Default,

Transcode keys to a new keys type representation Read more
source§

fn nodes<N, const D: usize>() -> NodeIter<Self, N, D>
where N: Transcode + Default,

Return an iterator over nodes of a given type Read more
source§

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,

Serialize a node by keys. Read more
source§

impl<T: Copy + ?Sized> Copy for StrLeaf<T>

source§

impl<T: Eq + ?Sized> Eq for StrLeaf<T>

source§

impl<T: ?Sized> StructuralPartialEq for StrLeaf<T>

Auto Trait Implementations§

§

impl<T> Freeze for StrLeaf<T>
where T: Freeze + ?Sized,

§

impl<T> RefUnwindSafe for StrLeaf<T>
where T: RefUnwindSafe + ?Sized,

§

impl<T> Send for StrLeaf<T>
where T: Send + ?Sized,

§

impl<T> Sync for StrLeaf<T>
where T: Sync + ?Sized,

§

impl<T> Unpin for StrLeaf<T>
where T: Unpin + ?Sized,

§

impl<T> UnwindSafe for StrLeaf<T>
where T: UnwindSafe + ?Sized,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<!> for T

source§

fn from(t: !) -> T

Converts to this type from the input type.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

source§

impl<T> TreeDeserializeOwned for T
where T: for<'de> TreeDeserialize<'de>,