toasty_core/stmt/
entry_path.rs

1use super::{Projection, projection};
2
3/// A path that can be used to navigate into a composite [`Value`](super::Value)
4/// or [`Expr`](super::Expr).
5///
6/// Implemented for `usize` (single-step navigation) and `&Projection`
7/// (multi-step navigation).
8///
9/// # Examples
10///
11/// ```ignore
12/// use toasty_core::stmt::{Value, ValueRecord};
13///
14/// let record = Value::record_from_vec(vec![Value::from(1_i64), Value::from(2_i64)]);
15/// // Navigate with a single usize step
16/// let entry = record.entry(0_usize);
17/// ```
18pub trait EntryPath {
19    /// The iterator type yielding each step index.
20    type Iter: Iterator<Item = usize>;
21
22    /// Returns an iterator over the step indices.
23    fn step_iter(self) -> Self::Iter;
24}
25
26impl EntryPath for usize {
27    type Iter = std::option::IntoIter<Self>;
28
29    fn step_iter(self) -> Self::Iter {
30        Some(self).into_iter()
31    }
32}
33
34impl<'a> EntryPath for &'a Projection {
35    type Iter = projection::Iter<'a>;
36
37    fn step_iter(self) -> Self::Iter {
38        self.into_iter()
39    }
40}