use crate::{module::Event, request::Payload, response::EventResponse}; use derivative::*; use std::{ fmt::{Debug, Display}, hash::Hash, }; // #[derive(Debug)] // pub struct SenderPayload { // pub(crate) payload: Payload, // pub(crate) event: Event, // } // // impl SenderPayload { // pub fn new(event: E) -> SenderPayload // where // E: Eq + Hash + Debug + Clone + Display, // { // Self { // event: event.into(), // payload: Payload::None, // } // } // // pub fn payload(mut self, payload: Payload) -> Self { // self.payload = payload; // self // } // // pub fn from_bytes(bytes: Vec) -> Self { unimplemented!() } // } // // impl std::convert::Into for SenderPayload { // fn into(self) -> ModuleRequest { // ModuleRequest::new(self.event).payload(self.payload) } } // // impl std::default::Default for SenderPayload { // fn default() -> Self { SenderPayload::new("").payload(Payload::None) } // } // // impl std::convert::Into for SenderPayload { // fn into(self) -> EventRequest { unimplemented!() } // } pub type BoxStreamCallback = Box; // #[derive(Debug)] // pub struct SenderRequest2 // where // T: 'static + Debug, // C: FnOnce(T, EventResponse) + 'static, // { // pub config: T, // pub event: Event, // pub payload: Option, // pub callback: Box, // } #[derive(Derivative)] #[derivative(Debug)] pub struct SenderRequest where T: 'static + Debug, { pub config: T, pub event: Event, pub payload: Option, #[derivative(Debug = "ignore")] pub callback: Option>, } impl SenderRequest where T: 'static + Debug, { pub fn new(config: T, event: E) -> Self where E: Eq + Hash + Debug + Clone + Display, { Self { config, payload: None, event: event.into(), callback: None, } } pub fn payload(mut self, payload: Payload) -> Self { self.payload = Some(payload); self } pub fn callback(mut self, callback: F) -> Self where F: FnOnce(T, EventResponse) + 'static + Send + Sync, { self.callback = Some(Box::new(callback)); self } }