use std::fmt;
#[derive(Debug)]
#[non_exhaustive]
pub enum Error {
Io(std::io::Error),
Serialize(rustorb_typesupport::Error),
Dynamic(rustorb_xtypes::Error),
AlreadyDeleted,
OutOfResources,
Timeout,
PreconditionNotMet,
Unsupported(&'static str),
Security(String),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Io(e) => write!(f, "I/O error: {e}"),
Error::Serialize(e) => write!(f, "cannot serialize the sample: {e}"),
Error::Dynamic(e) => write!(f, "dynamic type or data: {e}"),
Error::AlreadyDeleted => f.write_str("the participant was deleted"),
Error::OutOfResources => f.write_str("no more entity ids"),
Error::Timeout => f.write_str("timed out"),
Error::PreconditionNotMet => f.write_str("the instance is not registered"),
Error::Unsupported(what) => write!(f, "not supported: {what}"),
Error::Security(what) => write!(f, "security: {what}"),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::Io(e) => Some(e),
Error::Serialize(e) => Some(e),
Error::Dynamic(e) => Some(e),
_ => None,
}
}
}
impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Self {
Error::Io(e)
}
}
impl From<rustorb_typesupport::Error> for Error {
fn from(e: rustorb_typesupport::Error) -> Self {
Error::Serialize(e)
}
}
impl From<rustorb_xtypes::Error> for Error {
fn from(e: rustorb_xtypes::Error) -> Self {
Error::Dynamic(e)
}
}
pub type Result<T> = std::result::Result<T, Error>;