use batpak::event::EventKind;
pub trait EffectBackend {
fn append_event(&mut self, kind: EventKind, payload: &[u8]) -> Result<(), EffectError>;
fn read_event(&mut self, event_category: &str) -> Result<(), EffectError> {
let _ = event_category;
Err(EffectError::new(
"event reads are not supported by this effect backend",
))
}
fn query_projection(&mut self, projection_id: &str) -> Result<(), EffectError> {
let _ = projection_id;
Err(EffectError::new(
"projection queries are not supported by this effect backend",
))
}
fn emit_receipt(&mut self, receipt_kind: &str) -> Result<(), EffectError> {
let _ = receipt_kind;
Err(EffectError::new(
"receipt emission is not supported by this effect backend",
))
}
fn use_host_control(&mut self, control: &str) -> Result<(), EffectError> {
let _ = control;
Err(EffectError::new(
"host controls are not supported by this effect backend",
))
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct EffectError {
message: String,
}
impl EffectError {
#[must_use]
pub fn new(message: impl Into<String>) -> Self {
Self {
message: message.into(),
}
}
#[must_use]
pub fn message(&self) -> &str {
&self.message
}
}
impl std::fmt::Display for EffectError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "effect backend failure: {}", self.message)
}
}
impl std::error::Error for EffectError {}