From 3cb5973be2a394b14255aac78db8b97ee3dbe40a Mon Sep 17 00:00:00 2001 From: Henry Schimke Date: Fri, 16 Sep 2022 17:05:57 -0500 Subject: [PATCH] impl Error for Exceptions --- src/exceptions.rs | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/src/exceptions.rs b/src/exceptions.rs index 592282e..cd2dcb1 100644 --- a/src/exceptions.rs +++ b/src/exceptions.rs @@ -1,4 +1,4 @@ -use std::fmt; +use std::{error::Error, fmt}; #[derive(Debug)] pub enum Exceptions { @@ -7,13 +7,42 @@ pub enum Exceptions { IllegalStateException(String), ArithmeticException(String), NotFoundException(String), - FormatException(String), - ChecksumException(String), + FormatException(String), + ChecksumException(String), ReaderException(String), WriterException(String), ReedSolomonException(String), IndexOutOfBoundsException(String), RuntimeException(String), ParseException(String), - ReaderDecodeException() -} \ No newline at end of file + ReaderDecodeException(), +} + +impl fmt::Display for Exceptions { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Exceptions::IllegalArgumentException(a) => { + write!(f, "IllegalArgumentException - {}", a) + } + Exceptions::UnsupportedOperationException(a) => { + write!(f, "UnsupportedOperationException - {}", a) + } + Exceptions::IllegalStateException(a) => write!(f, "IllegalStateException - {}", a), + Exceptions::ArithmeticException(a) => write!(f, "ArithmeticException - {}", a), + Exceptions::NotFoundException(a) => write!(f, "NotFoundException - {}", a), + Exceptions::FormatException(a) => write!(f, "FormatException - {}", a), + Exceptions::ChecksumException(a) => write!(f, "ChecksumException - {}", a), + Exceptions::ReaderException(a) => write!(f, "ReaderException - {}", a), + Exceptions::WriterException(a) => write!(f, "WriterException - {}", a), + Exceptions::ReedSolomonException(a) => write!(f, "ReedSolomonException - {}", a), + Exceptions::IndexOutOfBoundsException(a) => { + write!(f, "IndexOutOfBoundsException - {}", a) + } + Exceptions::RuntimeException(a) => write!(f, "RuntimeException - {}", a), + Exceptions::ParseException(a) => write!(f, "ParseException - {}", a), + Exceptions::ReaderDecodeException() => write!(f, "ReaderDecodeException - -"), + } + } +} + +impl Error for Exceptions {}