teascade-generator/src/error.rs

37 lines
736 B
Rust
Raw Normal View History

2018-04-16 15:58:16 +02:00
use std::convert::From;
use std::io::Error as IOError;
use std::error::Error as STDError;
use logger::LogLevel;
pub struct Error {
description: String,
severity: LogLevel,
}
impl Error {
pub fn new<T: Into<String>>(severity: LogLevel, description: T) -> Error {
Error {
severity,
description: description.into(),
}
}
pub fn description(&self) -> String {
self.description.clone()
}
pub fn severity(&self) -> LogLevel {
self.severity.clone()
}
}
impl From<IOError> for Error {
fn from(err: IOError) -> Error {
Error {
description: err.description().to_owned(),
severity: LogLevel::SEVERE,
}
}
}