relay_knowledge/ports/
worker_outbound.rs1use std::{error::Error, fmt, future::Future, pin::Pin};
2
3pub type WorkerOutboundFuture<'a> =
5 Pin<Box<dyn Future<Output = Result<serde_json::Value, WorkerOutboundError>> + Send + 'a>>;
6
7#[derive(Debug, Clone, PartialEq, Eq)]
9pub struct WorkerOutboundError {
10 pub message: String,
11}
12
13impl fmt::Display for WorkerOutboundError {
14 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
15 formatter.write_str(&self.message)
16 }
17}
18
19impl Error for WorkerOutboundError {}
20
21pub trait WorkerOutboundPort: Send + Sync {
23 fn post_json<'a>(
24 &'a self,
25 endpoint: &'a str,
26 payload: &'a serde_json::Value,
27 ) -> WorkerOutboundFuture<'a>;
28}
29
30#[cfg(test)]
31#[path = "worker_outbound_tests.rs"]
32mod tests;