megalodon/
streaming.rs

1//! Streaming modules
2use crate::entities as MegalodonEntities;
3use async_trait::async_trait;
4use std::future::Future;
5use std::pin::Pin;
6
7/// Streaming interface to listen message.
8#[async_trait]
9pub trait Streaming {
10    /// Start listening stream messages. When receive a message, the callback function will be called.
11    async fn listen(
12        &self,
13        callback: Box<
14            dyn Fn(Message) -> Pin<Box<dyn Future<Output = ()> + Send>>
15                + Send
16                + Sync
17                + 'async_trait,
18        >,
19    );
20}
21
22/// Stream message definitions.
23#[derive(Debug, Clone)]
24pub enum Message {
25    /// Update message for `update` event.
26    Update(MegalodonEntities::Status),
27    /// Notification message for `notification` evnet.
28    Notification(MegalodonEntities::Notification),
29    /// Conversation message for `conversation` event.
30    Conversation(MegalodonEntities::Conversation),
31    /// Delete message for `delete` event.
32    Delete(String),
33    /// StatusUpdate message of `status.update` event.
34    StatusUpdate(MegalodonEntities::Status),
35    /// Heartbeat for streaming connection.
36    Heartbeat(),
37}