garudust_core/
platform.rs1use std::pin::Pin;
2use std::sync::Arc;
3
4use async_trait::async_trait;
5use futures::Stream;
6
7use crate::{
8 error::PlatformError,
9 types::{ChannelId, InboundMessage, OutboundMessage},
10};
11
12#[async_trait]
13pub trait PlatformAdapter: Send + Sync + 'static {
14 fn name(&self) -> &'static str;
15
16 async fn start(&self, handler: Arc<dyn MessageHandler>) -> Result<(), PlatformError>;
17
18 async fn send_message(
19 &self,
20 channel: &ChannelId,
21 message: OutboundMessage,
22 ) -> Result<(), PlatformError>;
23
24 async fn send_stream(
25 &self,
26 channel: &ChannelId,
27 stream: Pin<Box<dyn Stream<Item = String> + Send>>,
28 ) -> Result<(), PlatformError>;
29}
30
31#[async_trait]
32pub trait MessageHandler: Send + Sync + 'static {
33 async fn handle(&self, msg: InboundMessage) -> Result<(), anyhow::Error>;
34}