Trait miniconf::TreeAny

source ·
pub trait TreeAny {
    // Required methods
    fn ref_any_by_key<K>(&self, keys: K) -> Result<&dyn Any, Traversal>
       where K: Keys;
    fn mut_any_by_key<K>(&mut self, keys: K) -> Result<&mut dyn Any, Traversal>
       where K: Keys;

    // Provided methods
    fn ref_by_key<T: Any, K: IntoKeys>(&self, keys: K) -> Result<&T, Traversal> { ... }
    fn mut_by_key<T: Any, K: IntoKeys>(
        &mut self,
        keys: K,
    ) -> Result<&mut T, Traversal> { ... }
}
Expand description

Access any node by keys.

This uses the dyn Any trait object.

use core::any::Any;
use miniconf::{Indices, IntoKeys, JsonPath, Leaf, TreeAny, TreeKey};
#[derive(TreeKey, TreeAny, Default)]
struct S {
    foo: Leaf<u32>,
    bar: [Leaf<u16>; 2],
};
let mut s = S::default();

for node in S::nodes::<Indices<[_; 2]>, 2>() {
    let (key, node) = node.unwrap();
    let a = s
        .ref_any_by_key(key.into_iter().take(node.depth()).into_keys())
        .unwrap();
    assert!([0u32.type_id(), 0u16.type_id()].contains(&(&*a).type_id()));
}

let val: &mut u16 = s.mut_by_key(&JsonPath::from(".bar[1]")).unwrap();
*val = 3;
assert_eq!(*s.bar[1], 3);

let val: &u16 = s.ref_by_key(&JsonPath::from(".bar[1]")).unwrap();
assert_eq!(*val, 3);

Required Methods§

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.

Provided Methods§

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.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<T0: TreeAny> TreeAny for (T0,)

source§

fn ref_any_by_key<K>(&self, keys: K) -> Result<&dyn Any, Traversal>
where K: Keys,

source§

fn mut_any_by_key<K>(&mut self, keys: K) -> Result<&mut dyn Any, Traversal>
where K: Keys,

source§

impl<T0: TreeAny, T1: TreeAny> TreeAny for (T0, T1)

source§

fn ref_any_by_key<K>(&self, keys: K) -> Result<&dyn Any, Traversal>
where K: Keys,

source§

fn mut_any_by_key<K>(&mut self, keys: K) -> Result<&mut dyn Any, Traversal>
where K: Keys,

source§

impl<T0: TreeAny, T1: TreeAny, T2: TreeAny> TreeAny for (T0, T1, T2)

source§

fn ref_any_by_key<K>(&self, keys: K) -> Result<&dyn Any, Traversal>
where K: Keys,

source§

fn mut_any_by_key<K>(&mut self, keys: K) -> Result<&mut dyn Any, Traversal>
where K: Keys,

source§

impl<T0: TreeAny, T1: TreeAny, T2: TreeAny, T3: TreeAny> TreeAny for (T0, T1, T2, T3)

source§

fn ref_any_by_key<K>(&self, keys: K) -> Result<&dyn Any, Traversal>
where K: Keys,

source§

fn mut_any_by_key<K>(&mut self, keys: K) -> Result<&mut dyn Any, Traversal>
where K: Keys,

source§

impl<T0: TreeAny, T1: TreeAny, T2: TreeAny, T3: TreeAny, T4: TreeAny> TreeAny for (T0, T1, T2, T3, T4)

source§

fn ref_any_by_key<K>(&self, keys: K) -> Result<&dyn Any, Traversal>
where K: Keys,

source§

fn mut_any_by_key<K>(&mut self, keys: K) -> Result<&mut dyn Any, Traversal>
where K: Keys,

source§

impl<T0: TreeAny, T1: TreeAny, T2: TreeAny, T3: TreeAny, T4: TreeAny, T5: TreeAny> TreeAny for (T0, T1, T2, T3, T4, T5)

source§

fn ref_any_by_key<K>(&self, keys: K) -> Result<&dyn Any, Traversal>
where K: Keys,

source§

fn mut_any_by_key<K>(&mut self, keys: K) -> Result<&mut dyn Any, Traversal>
where K: Keys,

source§

impl<T0: TreeAny, T1: TreeAny, T2: TreeAny, T3: TreeAny, T4: TreeAny, T5: TreeAny, T6: TreeAny> TreeAny for (T0, T1, T2, T3, T4, T5, T6)

source§

fn ref_any_by_key<K>(&self, keys: K) -> Result<&dyn Any, Traversal>
where K: Keys,

source§

fn mut_any_by_key<K>(&mut self, keys: K) -> Result<&mut dyn Any, Traversal>
where K: Keys,

source§

impl<T0: TreeAny, T1: TreeAny, T2: TreeAny, T3: TreeAny, T4: TreeAny, T5: TreeAny, T6: TreeAny, T7: TreeAny> TreeAny for (T0, T1, T2, T3, T4, T5, T6, T7)

source§

fn ref_any_by_key<K>(&self, keys: K) -> Result<&dyn Any, Traversal>
where K: Keys,

source§

fn mut_any_by_key<K>(&mut self, keys: K) -> Result<&mut dyn Any, Traversal>
where K: Keys,

source§

impl<T: TreeAny> TreeAny for &RefCell<T>

source§

fn ref_any_by_key<K>(&self, _keys: K) -> Result<&dyn Any, Traversal>
where K: Keys,

source§

fn mut_any_by_key<K>(&mut self, _keys: K) -> Result<&mut dyn Any, Traversal>
where K: Keys,

source§

impl<T: TreeAny> TreeAny for Bound<T>

source§

fn ref_any_by_key<K>(&self, keys: K) -> Result<&dyn Any, Traversal>
where K: Keys,

source§

fn mut_any_by_key<K>(&mut self, keys: K) -> Result<&mut dyn Any, Traversal>
where K: Keys,

source§

impl<T: TreeAny> TreeAny for Option<T>

source§

fn ref_any_by_key<K>(&self, keys: K) -> Result<&dyn Any, Traversal>
where K: Keys,

source§

fn mut_any_by_key<K>(&mut self, keys: K) -> Result<&mut dyn Any, Traversal>
where K: Keys,

source§

impl<T: TreeAny> TreeAny for &mut T

source§

fn ref_any_by_key<K>(&self, keys: K) -> Result<&dyn Any, Traversal>
where K: Keys,

source§

fn mut_any_by_key<K>(&mut self, keys: K) -> Result<&mut dyn Any, Traversal>
where K: Keys,

source§

impl<T: TreeAny> TreeAny for Cell<T>

source§

fn ref_any_by_key<K>(&self, _keys: K) -> Result<&dyn Any, Traversal>
where K: Keys,

source§

fn mut_any_by_key<K>(&mut self, keys: K) -> Result<&mut dyn Any, Traversal>
where K: Keys,

source§

impl<T: TreeAny> TreeAny for RefCell<T>

source§

fn ref_any_by_key<K>(&self, _keys: K) -> Result<&dyn Any, Traversal>
where K: Keys,

source§

fn mut_any_by_key<K>(&mut self, keys: K) -> Result<&mut dyn Any, Traversal>
where K: Keys,

source§

impl<T: TreeAny> TreeAny for Range<T>

source§

fn ref_any_by_key<K>(&self, keys: K) -> Result<&dyn Any, Traversal>
where K: Keys,

source§

fn mut_any_by_key<K>(&mut self, keys: K) -> Result<&mut dyn Any, Traversal>
where K: Keys,

source§

impl<T: TreeAny> TreeAny for RangeFrom<T>

source§

fn ref_any_by_key<K>(&self, keys: K) -> Result<&dyn Any, Traversal>
where K: Keys,

source§

fn mut_any_by_key<K>(&mut self, keys: K) -> Result<&mut dyn Any, Traversal>
where K: Keys,

source§

impl<T: TreeAny> TreeAny for RangeTo<T>

source§

fn ref_any_by_key<K>(&self, keys: K) -> Result<&dyn Any, Traversal>
where K: Keys,

source§

fn mut_any_by_key<K>(&mut self, keys: K) -> Result<&mut dyn Any, Traversal>
where K: Keys,

source§

impl<T: TreeAny, E: TreeAny> TreeAny for Result<T, E>

source§

fn ref_any_by_key<K>(&self, keys: K) -> Result<&dyn Any, Traversal>
where K: Keys,

source§

fn mut_any_by_key<K>(&mut self, keys: K) -> Result<&mut dyn Any, Traversal>
where K: Keys,

source§

impl<T: TreeAny, const N: usize> TreeAny for [T; N]

source§

fn ref_any_by_key<K>(&self, keys: K) -> Result<&dyn Any, Traversal>
where K: Keys,

source§

fn mut_any_by_key<K>(&mut self, keys: K) -> Result<&mut dyn Any, Traversal>
where K: Keys,

Implementors§

source§

impl<T> TreeAny for StrLeaf<T>

source§

impl<T: Any> TreeAny for Leaf<T>