use std::{fmt, io};
#[derive(Debug)]
pub enum TraciError {
Connection(io::Error),
Protocol(String),
SimulationError(String),
NotImplemented(String),
SimulationEnd,
}
impl fmt::Display for TraciError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TraciError::Connection(e) => write!(f, "TraCI connection error: {e}"),
TraciError::Protocol(msg) => write!(f, "TraCI protocol error: {msg}"),
TraciError::SimulationError(msg) => write!(f, "TraCI simulation error: {msg}"),
TraciError::NotImplemented(msg) => write!(f, "TraCI command not implemented: {msg}"),
TraciError::SimulationEnd => write!(f, "SUMO simulation ended"),
}
}
}
impl std::error::Error for TraciError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
TraciError::Connection(e) => Some(e),
_ => None,
}
}
}
impl From<io::Error> for TraciError {
fn from(e: io::Error) -> Self {
TraciError::Connection(e)
}
}