Skip to main content

scientific_workflow/
composition.rs

1//! Crate-owned composition of active Runtime mechanics and automatic UI.
2
3use crate::runtime::{RunSummary, RuntimeError};
4use crate::study::Study;
5#[cfg(feature = "terminal-ui")]
6use crate::ui::UiSession;
7
8#[cfg(not(feature = "terminal-ui"))]
9use crate::runtime::{PresentationFailure, RuntimeEvent, RuntimeObserver};
10
11/// Executes a validated Study with Workflow's automatic presentation adapter.
12pub fn execute(study: Study) -> Result<RunSummary, RuntimeError> {
13    #[cfg(feature = "terminal-ui")]
14    {
15        crate::runtime::execute_with_observer(study, || {
16            UiSession::automatic().map_err(|source| Box::new(source) as _)
17        })
18    }
19
20    #[cfg(not(feature = "terminal-ui"))]
21    {
22        crate::runtime::execute_with_observer(study, || Ok(SilentObserver))
23    }
24}
25
26/// Observer used only by explicitly headless, no-default-feature builds.
27#[cfg(not(feature = "terminal-ui"))]
28struct SilentObserver;
29
30#[cfg(not(feature = "terminal-ui"))]
31impl RuntimeObserver for SilentObserver {
32    fn publish(&self, _event: RuntimeEvent<'_>) -> Result<(), PresentationFailure> {
33        Ok(())
34    }
35
36    fn cancellation_requested(&self) -> Result<bool, PresentationFailure> {
37        Ok(false)
38    }
39
40    fn finish(&self) -> Result<(), PresentationFailure> {
41        Ok(())
42    }
43}