Simply Coordinator/Processors::send by accepting impl Into *Message

This commit is contained in:
Luke Parker
2023-09-29 04:19:59 -04:00
parent 0eff3d9453
commit bd5491dfd5
7 changed files with 69 additions and 89 deletions

View File

@@ -10,14 +10,15 @@ pub struct Message {
#[async_trait::async_trait]
pub trait Coordinator {
async fn send(&mut self, msg: ProcessorMessage);
async fn send(&mut self, msg: impl Send + Into<ProcessorMessage>);
async fn recv(&mut self) -> Message;
async fn ack(&mut self, msg: Message);
}
#[async_trait::async_trait]
impl Coordinator for MessageQueue {
async fn send(&mut self, msg: ProcessorMessage) {
async fn send(&mut self, msg: impl Send + Into<ProcessorMessage>) {
let msg: ProcessorMessage = msg.into();
let metadata = Metadata { from: self.service, to: Service::Coordinator, intent: msg.intent() };
let msg = serde_json::to_string(&msg).unwrap();