src/error.rs

Wed, 07 Dec 2022 06:57:26 +0200

author
Tuomo Valkonen <tuomov@iki.fi>
date
Wed, 07 Dec 2022 06:57:26 +0200
changeset 17
51bfde513cfa
parent 5
59dc4c5883f4
permissions
-rw-r--r--

README beautification

5
59dc4c5883f4 Improve documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 4
diff changeset
1 /*!
59dc4c5883f4 Improve documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 4
diff changeset
2 Error passing helper types
59dc4c5883f4 Improve documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 4
diff changeset
3 */
0
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
4
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
5 use std::error::Error;
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
6
5
59dc4c5883f4 Improve documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 4
diff changeset
7 /// A [`Result`] containing `T` or a dynamic error type
0
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
8 pub type DynResult<T> = Result<T, Box<dyn Error>>;
5
59dc4c5883f4 Improve documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 4
diff changeset
9
59dc4c5883f4 Improve documentation
Tuomo Valkonen <tuomov@iki.fi>
parents: 4
diff changeset
10 /// A [`Result`] containing `()` or a dynamic error type
0
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
11 pub type DynError = DynResult<()>;
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
12
4
61b068c50e25 Added type for numerical errors
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
13 #[derive(Clone, Debug)]
61b068c50e25 Added type for numerical errors
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
14 /// Type for numerical errors.
61b068c50e25 Added type for numerical errors
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
15 pub struct NumericalError(
61b068c50e25 Added type for numerical errors
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
16 /// Provides additional information about the error
61b068c50e25 Added type for numerical errors
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
17 pub &'static str
61b068c50e25 Added type for numerical errors
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
18 );
0
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
19
4
61b068c50e25 Added type for numerical errors
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
20 impl std::fmt::Display for NumericalError {
61b068c50e25 Added type for numerical errors
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
21 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
61b068c50e25 Added type for numerical errors
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
22 match self.0 {
61b068c50e25 Added type for numerical errors
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
23 "" => write!(f, "Numerical error"),
61b068c50e25 Added type for numerical errors
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
24 s => write!(f, "{s}"),
61b068c50e25 Added type for numerical errors
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
25 }
61b068c50e25 Added type for numerical errors
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
26 }
61b068c50e25 Added type for numerical errors
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
27 }
0
9f27689eb130 Initialise new clean repository
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
28
4
61b068c50e25 Added type for numerical errors
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
29 impl std::error::Error for NumericalError {}

mercurial