update to 2018 edition and remove custom error and result types

master
rasul 4 years ago
parent 8150dc2b1f
commit a344423ba3

@ -1,32 +0,0 @@
use std::fmt::{Display, Formatter, Result as FmtResult};
use log::SetLoggerError;
pub type RagResult<T> = Result<T, RagError>;
#[derive(Debug)]
pub enum RagError {
SetLogger(SetLoggerError),
Empty,
}
impl From<()> for RagError {
fn from(_: ()) -> RagError {
RagError::Empty
}
}
impl From<SetLoggerError> for RagError {
fn from(e: SetLoggerError) -> RagError {
RagError::SetLogger(e)
}
}
impl Display for RagError {
fn fmt(&self, f: &mut Formatter) -> FmtResult {
match *self {
RagError::SetLogger(ref e) => Display::fmt(e, f),
RagError::Empty => Display::fmt("Empty", f),
}
}
}

@ -1,19 +1,13 @@
/// Logger implementation for colors in the terminal and in the future /// Logger implementation for colors in the terminal and in the future
/// logging to a file and to a remote log server /// logging to a file and to a remote log server
extern crate chrono;
extern crate colored;
extern crate log;
use colored::*; use colored::*;
use log::{set_logger, set_max_level, Log, Level, LevelFilter, Metadata, Record}; use log::{set_logger, set_max_level, Log, Level, LevelFilter, Metadata, Record, SetLoggerError};
pub mod error; pub mod error;
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;
pub use error::RagError;
pub use error::RagResult;
static LOGGER: Logger = Logger; static LOGGER: Logger = Logger;
struct Logger; struct Logger;
@ -57,7 +51,7 @@ impl Log for Logger {
fn flush(&self) {} fn flush(&self) {}
} }
pub fn init() -> RagResult<()> { pub fn init() -> Result<(), SetLoggerError> {
Ok(set_logger(&LOGGER).map(|()| set_max_level(LevelFilter::Info))?) Ok(set_logger(&LOGGER).map(|()| set_max_level(LevelFilter::Info))?)
} }

Loading…
Cancel
Save