Implement standard Error trait for SqliteError

This commit is contained in:
Joshua Schneider 2015-02-04 21:08:44 +01:00
parent 4ca7b4964f
commit 6d795caaed

View File

@ -57,6 +57,7 @@ extern crate libc;
use std::mem; use std::mem;
use std::ptr; use std::ptr;
use std::fmt; use std::fmt;
use std::error;
use std::rc::{Rc}; use std::rc::{Rc};
use std::cell::{RefCell, Cell}; use std::cell::{RefCell, Cell};
use std::ffi::{CString}; use std::ffi::{CString};
@ -100,8 +101,14 @@ pub struct SqliteError {
} }
impl fmt::Display for SqliteError { impl fmt::Display for SqliteError {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "SqliteError( code: {}, message: {} )", self.code, self.message) write!(f, "{} (SQLite error {})", self.message, self.code)
}
}
impl error::Error for SqliteError {
fn description(&self) -> &str {
ffi::code_to_str(self.code)
} }
} }