sim_lib_expr_tree/
inspect.rs1use std::sync::Arc;
4
5use sim_expr_tree_calc::{CalcReceipt, CalcStatus, EncodedFace};
6use sim_kernel::{Error, Result};
7
8use crate::TreeHandle;
9
10#[derive(Clone, Copy, Debug, Eq, PartialEq)]
12pub enum TreeEntryKind {
13 Directory,
15 Cell,
17 Mount,
19}
20
21#[derive(Clone, Debug, Eq, PartialEq)]
23pub struct TreeEntryInspection {
24 pub path: String,
26 pub name: String,
28 pub kind: TreeEntryKind,
30 pub revision: u64,
32}
33
34#[derive(Clone, Debug, Eq, PartialEq)]
36pub struct TreeCellInspection {
37 pub path: String,
39 pub source: EncodedFace,
41 pub result: EncodedFace,
43 pub status: CalcStatus,
45 pub source_revision: u64,
47 pub receipt: Option<CalcReceipt>,
49 pub policy_badges: Vec<String>,
51}
52
53impl TreeHandle {
54 pub fn storage_name(&self) -> Result<String> {
56 self.with_state(|state| Ok(state.storage_name().to_owned()))
57 }
58
59 pub fn inspect_entries(&self, path: &str) -> Result<Vec<TreeEntryInspection>> {
61 self.with_state(|state| state.inspect_entries(path))
62 }
63
64 pub fn inspect_cell(&self, path: &str) -> Result<TreeCellInspection> {
66 self.with_state(|state| state.inspect_cell(path))
67 }
68
69 pub fn set_wall_clock(&self, clock: Arc<dyn sim_host_core::WallClock>) -> Result<()> {
73 self.with_state(|state| {
74 state.set_wall_clock(clock);
75 Ok(())
76 })
77 }
78
79 fn with_state<T>(
80 &self,
81 action: impl FnOnce(&mut crate::runtime::TreeState) -> std::result::Result<T, String>,
82 ) -> Result<T> {
83 let mut state = self
84 .state
85 .lock()
86 .map_err(|_| Error::Eval("expression-tree state poisoned".to_owned()))?;
87 action(&mut state).map_err(Error::Eval)
88 }
89}