use std::pin::Pin;
use anyhow::Result;
use super::action::{Action, ActionSpec, ExecCtx, Screenshot};
#[derive(Debug, Clone)]
pub struct ActionOutput {
pub ok: bool,
pub message: Option<String>,
}
impl ActionOutput {
pub fn ok() -> Self {
Self {
ok: true,
message: None,
}
}
pub fn err(msg: impl Into<String>) -> Self {
Self {
ok: false,
message: Some(msg.into()),
}
}
}
pub type ActionFut<'a> = Pin<Box<dyn Future<Output = Result<ActionOutput>> + Send + 'a>>;
pub type ScreenshotFut<'a> = Pin<Box<dyn Future<Output = Result<Screenshot>> + Send + 'a>>;
pub trait Operator: Send + Sync {
fn name(&self) -> &'static str;
fn action_spaces(&self) -> Vec<ActionSpec>;
fn screenshot(&self) -> ScreenshotFut<'_>;
fn execute<'a>(&'a self, action: &'a Action, ctx: &'a ExecCtx) -> ActionFut<'a>;
}