use polariton::operation::{ParameterTable, OperationResponse};
pub struct Immediate<const CODE: u8, U: Send + Sync, C: Clone + Send + Sync + 'static = ()> {
_user_ty: std::marker::PhantomData<U>,
_custom_ty: std::marker::PhantomData<C>,
const_data: ParameterTable<C>,
}
impl <const CODE: u8, U: Send + Sync, C: Clone + Send + Sync + 'static> Immediate<CODE, U, C> {
pub fn new<F: FnOnce() -> ParameterTable<C>>(f: F) -> Self {
Self {
_user_ty: std::marker::PhantomData::default(),
_custom_ty: std::marker::PhantomData::default(),
const_data: f(),
}
}
}
#[cfg_attr(feature = "async", async_trait::async_trait)]
impl <const CODE: u8, U: Send + Sync, C: Clone + Send + Sync + 'static> super::Operation<C> for Immediate<CODE, U, C> {
type User = U;
fn handle(&self, _: polariton::operation::ParameterTable<C>, _: &Self::User) -> OperationResponse<C> {
OperationResponse {
code: CODE,
return_code: 0,
message: polariton::operation::Typed::Null,
params: self.const_data.clone(),
}
}
#[cfg(feature = "async")]
async fn handle_async(&self, p: polariton::operation::ParameterTable<C>, u: &Self::User) -> polariton::operation::OperationResponse<C> {
self.handle(p, u)
}
}
impl <const CODE: u8, U: Send + Sync, C: Clone + Send + Sync> super::OperationCode for Immediate<CODE, U, C> {
fn op_code() -> u8 {
CODE
}
}