Skip to main content

vantage_table/table/impls/
traverse.rs

1//! The shared `get_ref` body of drivers whose relations are typed
2//! `with_one` / `with_many` joins.
3
4use ciborium::Value as CborValue;
5use vantage_core::Result;
6use vantage_types::{EmptyEntity, Entity, Record};
7use vantage_vista::{Reference, Vista};
8
9use crate::{table::Table, traits::table_source::TableSource};
10
11impl<T: TableSource + 'static, E: Entity<T::Value> + 'static> Table<T, E> {
12    /// Traverse `reference`, a relation from this table's Vista metadata.
13    /// The bare target is built from the typed relation of the same name,
14    /// turned into a `Vista` by `wrap` (the driver's factory), then narrowed
15    /// by the reference's join keys when a parent `row` is given.
16    pub fn traverse_erased(
17        &self,
18        reference: &Reference,
19        row: Option<&Record<CborValue>>,
20        wrap: impl FnOnce(Table<T, EmptyEntity>) -> Result<Vista>,
21    ) -> Result<Vista> {
22        let target = wrap(self.get_ref_target_erased(&reference.name)?)?;
23        match row {
24            Some(row) => reference.narrow(target, row),
25            None => Ok(target),
26        }
27    }
28}