From 3e27279dc80533a1dcd79685b59bad89fa44924a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vuka=C5=A1in=20Stepanovi=C4=87?= Date: Wed, 15 Feb 2023 07:47:20 +0000 Subject: [PATCH] add exception factories --- src/exceptions.rs | 106 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/src/exceptions.rs b/src/exceptions.rs index b0c4c30..6b613d5 100644 --- a/src/exceptions.rs +++ b/src/exceptions.rs @@ -22,6 +22,112 @@ pub enum Exceptions { ReaderDecodeException(), } +impl Exceptions { + pub fn illegalArgument>(x: I) -> Self { + Self::IllegalArgumentException(Some(x.into())) + } + + pub fn illegalArgumentEmpty() -> Self { + Self::IllegalArgumentException(None) + } + + pub fn unsupportedOperation>(x: I) -> Self { + Self::UnsupportedOperationException(Some(x.into())) + } + + pub fn unsupportedOperationEmpty() -> Self { + Self::UnsupportedOperationException(None) + } + + pub fn illegalState>(x: I) -> Self { + Self::IllegalStateException(Some(x.into())) + } + + pub fn illegalStateEmpty() -> Self { + Self::IllegalStateException(None) + } + + pub fn arithmetic>(x: I) -> Self { + Self::ArithmeticException(Some(x.into())) + } + + pub fn arithmeticEmpty() -> Self { + Self::ArithmeticException(None) + } + + pub fn notFound>(x: I) -> Self { + Self::NotFoundException(Some(x.into())) + } + + pub fn notFoundEmpty() -> Self { + Self::NotFoundException(None) + } + + pub fn format>(x: I) -> Self { + Self::FormatException(Some(x.into())) + } + + pub fn formatEmpty() -> Self { + Self::FormatException(None) + } + + pub fn checksum>(x: I) -> Self { + Self::ChecksumException(Some(x.into())) + } + + pub fn checksumEmpty() -> Self { + Self::ChecksumException(None) + } + + pub fn reader>(x: I) -> Self { + Self::ReaderException(Some(x.into())) + } + + pub fn readerEmpty() -> Self { + Self::ReaderException(None) + } + + pub fn writer>(x: I) -> Self { + Self::WriterException(Some(x.into())) + } + + pub fn writerEmpty() -> Self { + Self::WriterException(None) + } + + pub fn reedSolomon>(x: I) -> Self { + Self::ReedSolomonException(Some(x.into())) + } + + pub fn reedSolomonEmpty() -> Self { + Self::ReedSolomonException(None) + } + + pub fn indexOutOfBounds>(x: I) -> Self { + Self::IndexOutOfBoundsException(Some(x.into())) + } + + pub fn indexOutOfBoundsEmpty() -> Self { + Self::IndexOutOfBoundsException(None) + } + + pub fn runtime>(x: I) -> Self { + Self::RuntimeException(Some(x.into())) + } + + pub fn runtimeEmpty() -> Self { + Self::RuntimeException(None) + } + + pub fn parse>(x: I) -> Self { + Self::ParseException(Some(x.into())) + } + + pub fn parseEmpty() -> Self { + Self::ParseException(None) + } +} + impl fmt::Display for Exceptions { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self {