use std::sync::MutexGuard;
use crate::graph::Graph;
use crate::{Engine, EngineError, Retention, Workspace};
pub trait Command {
type Output;
fn run(self, cx: &mut Context<'_>) -> Result<Self::Output, EngineError>;
}
pub struct Context<'a> {
pub(crate) graph: MutexGuard<'a, Graph>,
pub(crate) workspace: &'a Workspace,
engine: &'a Engine,
}
impl<'a> Context<'a> {
pub(crate) fn new(engine: &'a Engine, graph: MutexGuard<'a, Graph>) -> Self {
Self {
graph,
workspace: engine.workspace(),
engine,
}
}
pub(crate) fn staged(&self) -> (Engine, Workspace) {
let staging = self.workspace.staged();
let engine = Engine::new(staging.clone(), self.engine.languages().clone())
.with_retention(Retention::PerCall);
(engine, staging)
}
}