sim_lib_expr_tree/
inspect.rs1use sim_expr_tree_calc::{CalcReceipt, CalcStatus, EncodedFace};
4use sim_kernel::{Error, Result};
5
6use crate::TreeHandle;
7
8#[derive(Clone, Copy, Debug, Eq, PartialEq)]
10pub enum TreeEntryKind {
11 Directory,
13 Cell,
15 Mount,
17}
18
19#[derive(Clone, Debug, Eq, PartialEq)]
21pub struct TreeEntryInspection {
22 pub path: String,
24 pub name: String,
26 pub kind: TreeEntryKind,
28 pub revision: u64,
30}
31
32#[derive(Clone, Debug, Eq, PartialEq)]
34pub struct TreeCellInspection {
35 pub path: String,
37 pub source: EncodedFace,
39 pub result: EncodedFace,
41 pub status: CalcStatus,
43 pub source_revision: u64,
45 pub receipt: Option<CalcReceipt>,
47 pub policy_badges: Vec<String>,
49}
50
51impl TreeHandle {
52 pub fn storage_name(&self) -> Result<String> {
54 self.with_state(|state| Ok(state.storage_name().to_owned()))
55 }
56
57 pub fn inspect_entries(&self, path: &str) -> Result<Vec<TreeEntryInspection>> {
59 self.with_state(|state| state.inspect_entries(path))
60 }
61
62 pub fn inspect_cell(&self, path: &str) -> Result<TreeCellInspection> {
64 self.with_state(|state| state.inspect_cell(path))
65 }
66
67 pub fn set_wall_clock<F>(&self, clock: F) -> Result<()>
71 where
72 F: Fn() -> Option<u64> + Send + Sync + 'static,
73 {
74 self.with_state(|state| {
75 state.set_wall_clock(clock);
76 Ok(())
77 })
78 }
79
80 fn with_state<T>(
81 &self,
82 action: impl FnOnce(&mut crate::runtime::TreeState) -> std::result::Result<T, String>,
83 ) -> Result<T> {
84 let mut state = self
85 .state
86 .lock()
87 .map_err(|_| Error::Eval("expression-tree state poisoned".to_owned()))?;
88 action(&mut state).map_err(Error::Eval)
89 }
90}