-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6742505
commit acaf1cf
Showing
10 changed files
with
116 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "proton_err" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
name = "proton_err" | ||
path = "src/lib.rs" | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
//! Enumeration of Proton AP management errors. | ||
|
||
use std::{ | ||
error::Error, | ||
fmt::{ | ||
Display, | ||
Debug, | ||
Formatter, | ||
Result, | ||
}, | ||
}; | ||
|
||
#[derive(Debug)] | ||
/// An error that occurred within the Proton library. | ||
/// | ||
/// Note: this enumeration is exhaustive because of the `Other` variant. | ||
pub enum ProtonError<T> | ||
where T: Display + Debug | ||
{ | ||
/// An error that could not be converted to a native error. | ||
Other (T) | ||
} | ||
|
||
impl<T> Display for ProtonError<T> | ||
where T: Display + Debug | ||
{ | ||
fn fmt(&self, f: &mut Formatter<'_>) -> Result { | ||
use ProtonError::*; | ||
let error = match self { | ||
Other (t) => t.to_string(), | ||
}; | ||
|
||
write!(f, "{}", error) | ||
} | ||
} | ||
|
||
impl<T> Error for ProtonError<T> | ||
where T: Display + Debug { } | ||
|
||
impl From<Box<dyn Error>> for ProtonError<String> { | ||
fn from(e: Box<dyn Error>) -> ProtonError<String> { | ||
let string = if let Some (err) = e.source() { | ||
err.to_string() | ||
} else { | ||
String::new() | ||
}; | ||
|
||
ProtonError::<String>::Other (string) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
//! Error handling for the Proton access point management library. | ||
|
||
#![deny(warnings)] | ||
#![deny(missing_docs)] | ||
|
||
mod error; | ||
|
||
pub use error::ProtonError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters