use crate::protocol::dds::error::RtpsError;
#[derive(Debug)]
pub enum TransportError {
Io(std::io::Error),
Parse(RtpsError),
BufferTooSmall,
InvalidLocator,
}
impl core::fmt::Display for TransportError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Io(e) => write!(f, "transport I/O error: {e}"),
Self::Parse(e) => write!(f, "RTPS parse error: {e}"),
Self::BufferTooSmall => write!(f, "buffer too small for RTPS message"),
Self::InvalidLocator => write!(f, "locator kind not supported for UDP transport"),
}
}
}
impl std::error::Error for TransportError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Io(e) => Some(e),
_ => None,
}
}
}
impl From<std::io::Error> for TransportError {
fn from(e: std::io::Error) -> Self {
Self::Io(e)
}
}
impl From<RtpsError> for TransportError {
fn from(e: RtpsError) -> Self {
Self::Parse(e)
}
}