Created
January 8, 2019 19:04
-
-
Save detro/16f95ae5cff5fe818fc8a654eaba7732 to your computer and use it in GitHub Desktop.
Is there a better way to write this?
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
use http::Error as HttpError; | |
use std::{fmt, error}; | |
type Result<T> = std::result::Result<T, ResolutionError>; | |
/// A type of `Error` emitted by `Resolver` | |
/// | |
/// It contains a description and an optional `HttpError` that might have caused it | |
#[derive(Debug)] | |
pub struct ResolutionError { | |
desc: &'static str, | |
src: Option<HttpError>, | |
} | |
impl fmt::Display for ResolutionError { | |
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | |
write!(f, "ResolutionError: {}", self.desc) | |
} | |
} | |
impl error::Error for ResolutionError { | |
fn source(&self) -> Option<&(dyn error::Error + 'static)> { | |
match &self.src { //< I find this match especially annoying and puzzling, but I couldn't find a better way | |
Some(src) => Some(src), | |
None => None | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment