use crate::counter::Counter;
use crate::error::{invalid_state, PolarError, PolarResult};
use crate::events::QueryEvent;
use crate::terms::Term;
pub trait Runnable {
fn run(&mut self, _counter: Option<&mut Counter>) -> PolarResult<QueryEvent>;
fn external_question_result(&mut self, _call_id: u64, _answer: bool) -> PolarResult<()> {
invalid_state("Unexpected query answer")
}
fn external_call_result(&mut self, _call_id: u64, _term: Option<Term>) -> PolarResult<()> {
invalid_state("Unexpected external call")
}
fn debug_command(&mut self, _command: &str) -> PolarResult<()> {
invalid_state("Unexpected debug command")
}
fn handle_error(&mut self, err: PolarError) -> PolarResult<QueryEvent> {
Err(err)
}
fn clone_runnable(&self) -> Box<dyn Runnable>;
}
impl Clone for Box<dyn Runnable> {
fn clone(&self) -> Self {
(*self).clone_runnable()
}
}
impl std::fmt::Debug for Box<dyn Runnable> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, "Box<dyn Runnable>")
}
}