use std::fmt;
use std::sync::Arc;
#[derive(Debug, thiserror::Error)]
pub enum IpcError {
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("endpoint not ready (publisher has not advertised yet)")]
NotReady,
#[error("peer gone")]
PeerGone,
#[error("schema mismatch: expected {expected}, got {actual}")]
SchemaMismatch {
expected: String,
actual: String,
},
#[error("role mismatch: expected {expected}, got {actual}")]
RoleMismatch {
expected: String,
actual: String,
},
#[error("invalid endpoint uri: {0}")]
InvalidUri(String),
#[error("rendezvous error: {0}")]
Rendezvous(String),
#[error("serde error: {0}")]
Serde(String),
#[error("protocol error: {0}")]
Protocol(String),
}
pub type IpcResult<T> = Result<T, IpcError>;
pub trait IpcTransport: Send + Sync {
fn kind(&self) -> &'static str;
fn publish(&self, bytes: &[u8]) -> IpcResult<()>;
fn try_recv(&self) -> IpcResult<Option<Vec<u8>>>;
fn is_ready(&self) -> bool {
true
}
}
pub type IpcTransportHandle = Arc<dyn IpcTransport>;
impl fmt::Debug for dyn IpcTransport {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("IpcTransport")
.field("kind", &self.kind())
.finish()
}
}