use async_trait::async_trait; use mtp::codec::CommunicationValue; use std::time::Duration; #[derive(Clone, Debug, PartialEq, Eq)] pub enum OmikronError { Disconnected(String), Timeout(String), Authentication(String), Internal(String), } impl std::fmt::Display for OmikronError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Self::Disconnected(v) | Self::Timeout(v) | Self::Authentication(v) | Self::Internal(v) => f.write_str(v), } } } impl std::error::Error for OmikronError {} pub enum OmikronStartupError { Construction(String), InitialConnectionTimeout { connection: std::sync::Arc, }, Authentication, } #[async_trait] pub trait OmikronClient: Send + Sync { async fn send_message(&self, value: &CommunicationValue) -> Result<(), OmikronError>; async fn await_response( &self, value: &CommunicationValue, timeout: Duration, ) -> Result; async fn reconnect(&self) -> Result<(), OmikronError>; async fn is_connected(&self) -> bool; }