use std::fmt;
use std::sync::Arc;
use async_trait::async_trait;
use super::message::{ControlRequest, ControlResponse};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ControlTransportError {
pub code: String,
pub message: String,
}
impl ControlTransportError {
pub fn new(code: impl Into<String>, message: impl Into<String>) -> Self {
Self {
code: code.into(),
message: message.into(),
}
}
}
impl fmt::Display for ControlTransportError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}: {}", self.code, self.message)
}
}
impl std::error::Error for ControlTransportError {}
#[async_trait]
pub trait ControlTransport: Send + Sync {
fn id(&self) -> &'static str;
async fn send(&self, request: ControlRequest)
-> Result<ControlResponse, ControlTransportError>;
}
pub type DynControlTransport = Arc<dyn ControlTransport>;