use std::fmt::{Display, Formatter};
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug)]
pub enum Error {
RuntimeNotConfigured,
Unsupported(&'static str),
WouldBlock,
Timeout {
operation: &'static str,
timeout_ms: u64,
},
Serialization(String),
Protocol(String),
}
impl Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::RuntimeNotConfigured => write!(f, "jsmpi runtime is not configured"),
Self::Unsupported(message) => write!(f, "unsupported operation: {message}"),
Self::WouldBlock => write!(f, "operation would block in the current runtime"),
Self::Timeout {
operation,
timeout_ms,
} => write!(f, "{operation} timed out after {timeout_ms}ms"),
Self::Serialization(message) => write!(f, "serialization error: {message}"),
Self::Protocol(message) => write!(f, "protocol error: {message}"),
}
}
}
impl std::error::Error for Error {}