rt: Add error for instantiation
This commit is contained in:
parent
c48f3afcf4
commit
6b2502c4d7
2 changed files with 58 additions and 0 deletions
57
libimagrt/src/error.rs
Normal file
57
libimagrt/src/error.rs
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
use std::error::Error;
|
||||||
|
use std::fmt::Display;
|
||||||
|
use std::fmt::Formatter;
|
||||||
|
use std::fmt::Error as FmtError;
|
||||||
|
use std::clone::Clone;
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||||
|
pub enum RuntimeErrorKind {
|
||||||
|
Instantiate,
|
||||||
|
|
||||||
|
// more?
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct RuntimeError {
|
||||||
|
kind: RuntimeErrorKind,
|
||||||
|
cause: Option<Box<Error>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RuntimeError {
|
||||||
|
|
||||||
|
pub fn new(kind: RuntimeErrorKind, cause: Option<Box<Error>>) -> RuntimeError {
|
||||||
|
RuntimeError {
|
||||||
|
kind: kind,
|
||||||
|
cause: cause,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fn runtime_error_kind_as_str(e: &RuntimeErrorKind) -> &'static str {
|
||||||
|
match e {
|
||||||
|
&RuntimeErrorKind::Instantiate => "Could not instantiate",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for RuntimeError {
|
||||||
|
|
||||||
|
fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
|
||||||
|
try!(write!(fmt, "{}", runtime_error_kind_as_str(&self.kind)));
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Error for RuntimeError {
|
||||||
|
|
||||||
|
fn description(&self) -> &str {
|
||||||
|
runtime_error_kind_as_str(&self.kind)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn cause(&self) -> Option<&Error> {
|
||||||
|
self.cause.as_ref().map(|e| &**e)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ extern crate libimagstore;
|
||||||
extern crate libimagutil;
|
extern crate libimagutil;
|
||||||
|
|
||||||
mod configuration;
|
mod configuration;
|
||||||
|
mod error;
|
||||||
mod logger;
|
mod logger;
|
||||||
mod runtime;
|
mod runtime;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue