mirror of
https://gitlab.com/news-flash/article_scraper.git
synced 2025-07-08 08:30:00 +02:00
start refactor & fingerprints
This commit is contained in:
parent
29df3aa698
commit
273ddd832c
16 changed files with 944 additions and 848 deletions
59
src/full_text_parser/config/error.rs
Normal file
59
src/full_text_parser/config/error.rs
Normal file
|
@ -0,0 +1,59 @@
|
|||
use failure::{Backtrace, Context, Error, Fail};
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ConfigError {
|
||||
inner: Context<ConfigErrorKind>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Debug, Fail)]
|
||||
pub enum ConfigErrorKind {
|
||||
#[fail(display = "IO Error")]
|
||||
IO,
|
||||
#[fail(display = "Unknown Error")]
|
||||
Unknown,
|
||||
}
|
||||
|
||||
impl Fail for ConfigError {
|
||||
fn cause(&self) -> Option<&dyn Fail> {
|
||||
self.inner.cause()
|
||||
}
|
||||
|
||||
fn backtrace(&self) -> Option<&Backtrace> {
|
||||
self.inner.backtrace()
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for ConfigError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::Display::fmt(&self.inner, f)
|
||||
}
|
||||
}
|
||||
|
||||
// impl ConfigError {
|
||||
// pub fn kind(&self) -> ConfigErrorKind {
|
||||
// *self.inner.get_context()
|
||||
// }
|
||||
// }
|
||||
|
||||
impl From<ConfigErrorKind> for ConfigError {
|
||||
fn from(kind: ConfigErrorKind) -> ConfigError {
|
||||
ConfigError {
|
||||
inner: Context::new(kind),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Context<ConfigErrorKind>> for ConfigError {
|
||||
fn from(inner: Context<ConfigErrorKind>) -> ConfigError {
|
||||
ConfigError { inner }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Error> for ConfigError {
|
||||
fn from(_: Error) -> ConfigError {
|
||||
ConfigError {
|
||||
inner: Context::new(ConfigErrorKind::Unknown),
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue