use crate::types::{ActionId, BuildError, BuildOutput, Ctx, Sha256};
use async_trait::async_trait;
#[async_trait]
pub trait Action: Send + Sync {
fn id(&self) -> ActionId;
fn deps(&self) -> Vec<ActionId>;
async fn input_hash(&self, ctx: &Ctx) -> Result<Sha256, BuildError>;
async fn execute(&self, ctx: &Ctx) -> Result<BuildOutput, BuildError>;
}
#[cfg(test)]
mod tests {
use super::*;
struct MockAction;
#[async_trait]
impl Action for MockAction {
fn id(&self) -> ActionId {
ActionId("mock".to_string())
}
fn deps(&self) -> Vec<ActionId> {
vec![]
}
async fn input_hash(&self, _ctx: &Ctx) -> Result<Sha256, BuildError> {
Ok(Sha256([0; 32]))
}
async fn execute(&self, _ctx: &Ctx) -> Result<BuildOutput, BuildError> {
Ok(BuildOutput {
output_hash: Sha256([1; 32]),
stdout: String::new(),
})
}
}
#[test]
fn test_action_is_object_safe() {
let _action: Box<dyn Action> = Box::new(MockAction);
}
}