Skip to main content

relay_knowledge/ports/
worker_outbound.rs

1use std::{error::Error, fmt, future::Future, pin::Pin};
2
3/// Future returned by one bounded external worker request.
4pub type WorkerOutboundFuture<'a> =
5    Pin<Box<dyn Future<Output = Result<serde_json::Value, WorkerOutboundError>> + Send + 'a>>;
6
7/// Adapter-neutral failure returned by an external worker endpoint.
8#[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
21/// Bounded JSON transport used by worker orchestration.
22pub 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;