iota/omikron-connector/src/client.rs
2026-07-23 23:13:02 +02:00

43 lines
1.2 KiB
Rust

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<crate::omikron_connection::OmikronConnection>,
},
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<CommunicationValue, OmikronError>;
async fn reconnect(&self) -> Result<(), OmikronError>;
async fn is_connected(&self) -> bool;
}