use polariton::operation::{OperationResponse, ParameterTable, OperationRequest};
#[cfg_attr(feature = "async", async_trait::async_trait)]
pub trait Operation<C: Send + 'static>: Send + Sync {
type User: Sync;
#[cfg(not(feature = "async"))]
fn handle(&self, params: ParameterTable<C>, user: &Self::User) -> OperationResponse<C>;
#[cfg(feature = "async")]
fn handle(&self, _params: ParameterTable<C>, _user: &Self::User) -> OperationResponse<C> {
unreachable!()
}
#[cfg(feature = "async")]
async fn handle_async(&self, params: ParameterTable<C>, user: &Self::User) -> OperationResponse<C> {
self.handle(params, user)
}
}
pub trait OperationCode {
fn op_code() -> u8;
}
pub trait OperationModifier<C: Send + 'static>: Send + Sync {
fn before(&self, _req: &mut OperationRequest<C>, _flags: &mut u8) -> bool { true }
fn after(&self, _req: &mut OperationRequest<C>, _resp: &mut OperationResponse<C>, _flags: &mut u8) {}
}