pub enum ErrorKind {
EulerianTrailNotFound,
EulerianCircuitNotFound,
NegativeCycleDetected,
}
pub struct Error {
kind: ErrorKind,
msg: String,
}
impl Error {
pub fn new(kind: ErrorKind, msg: String) -> Self {
Error { kind, msg }
}
pub fn new_etnf() -> Self {
Error {
kind: ErrorKind::EulerianTrailNotFound,
msg: format!("Eulerian trail not found"),
}
}
pub fn new_ecnf() -> Self {
Error {
kind: ErrorKind::EulerianCircuitNotFound,
msg: format!("Eulerian circuit not found"),
}
}
pub fn new_ncd() -> Self {
Error {
kind: ErrorKind::NegativeCycleDetected,
msg: format!("Graph contains cycle"),
}
}
pub fn msg(&self) -> &str {
&self.msg
}
pub fn kind(&self) -> &ErrorKind {
&self.kind
}
}
impl std::fmt::Debug for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.msg())
}
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.msg())
}
}
impl std::error::Error for Error {}