harmos_sdk/operations/
surface.rs1use std::future::Future;
23
24use super::instance::Instance;
28use super::{CallContext, ContextError, ContextValue, OperationDeclaration, Response};
29use crate::operations::streams::Publish;
30use crate::{Message, StreamSpec};
31
32pub trait Host: Send + Sync + Sized {
47 type Error: std::error::Error + Send + Sync + 'static;
48
49 type Instance<O: OperationDeclaration>: Instance<O, Error = Self::Error>;
50
51 fn context(&self) -> &CallContext;
52
53 fn with_value<T: ContextValue>(&self, value: T) -> Result<Self, ContextError>;
54
55 fn submit<O: OperationDeclaration>(&self, request: O) -> impl Future<Output = Result<Self::Instance<O>, Self::Error>> + Send;
56
57 fn call<O: OperationDeclaration>(&self, request: O) -> impl Future<Output = Result<Response<O::Response>, Self::Error>> + Send;
58
59 fn submit_with_resources<O: OperationDeclaration<Response = ()>, R: Send + Sync + 'static>(
64 &self, request: O, resources: std::sync::Arc<R>,
65 ) -> impl Future<Output = Result<Self::Instance<O>, Self::Error>> + Send;
66
67 fn publish_on<S: StreamSpec>(&self, row: &S::Row) -> impl Future<Output = Result<(), Self::Error>> + Send
69 where
70 S::Row: Message,
71 {
72 let published = self.call(Publish {
73 stream: S::ID.to_owned(),
74 schema: S::VERSION,
75 sequence: None,
76 published_unix_micros: None,
77 context: None,
78 payload: row.encode_to_vec(),
79 following: Vec::new(),
80 });
81 async move {
82 published.await?;
83 Ok(())
84 }
85 }
86
87 fn publish<S: StreamSpec<Row = S> + Message>(&self, row: &S) -> impl Future<Output = Result<(), Self::Error>> + Send {
88 self.publish_on::<S>(row)
89 }
90}
91
92