miniconf

Trait 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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so 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 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 Deny<T>

Source§

impl<T> TreeAny for StrLeaf<T>

Source§

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