Added type for numerical errors

Mon, 24 Oct 2022 10:52:19 +0300

author
Tuomo Valkonen <tuomov@iki.fi>
date
Mon, 24 Oct 2022 10:52:19 +0300
changeset 4
61b068c50e25
parent 3
20db884b7028
child 5
59dc4c5883f4

Added type for numerical errors

src/error.rs file | annotate | diff | comparison | revisions
--- a/src/error.rs	Mon Oct 24 09:41:43 2022 +0300
+++ b/src/error.rs	Mon Oct 24 10:52:19 2022 +0300
@@ -4,5 +4,20 @@
 pub type DynResult<T> = Result<T, Box<dyn Error>>;
 pub type DynError = DynResult<()>;
 
+#[derive(Clone, Debug)]
+/// Type for numerical errors.
+pub struct NumericalError(
+    /// Provides additional information about the error
+    pub &'static str
+);
 
+impl std::fmt::Display for NumericalError {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        match self.0 {
+            "" => write!(f, "Numerical error"),
+            s => write!(f, "{s}"),
+        }
+    }
+}
 
+impl std::error::Error for NumericalError {}

mercurial