use std::panic::panic_any;
use qubit_function::Callable;
#[derive(Debug, Clone)]
pub enum TestCallableAction {
Return {
value: i32,
},
Fail {
error: &'static str,
},
Panic {
message: &'static str,
},
}
#[derive(Debug, Clone)]
pub struct TestCallable {
action: TestCallableAction,
}
impl TestCallable {
pub const fn returning(value: i32) -> Self {
Self {
action: TestCallableAction::Return { value },
}
}
pub const fn fail(error: &'static str) -> Self {
Self {
action: TestCallableAction::Fail { error },
}
}
pub const fn panic(message: &'static str) -> Self {
Self {
action: TestCallableAction::Panic { message },
}
}
}
impl Callable<i32, &'static str> for TestCallable {
fn call(&mut self) -> Result<i32, &'static str> {
match &self.action {
TestCallableAction::Return { value } => Ok(*value),
TestCallableAction::Fail { error } => Err(*error),
TestCallableAction::Panic { message } => panic_any(*message),
}
}
}