From 6d795caaedc233266a62966ef045ed7981248e21 Mon Sep 17 00:00:00 2001 From: Joshua Schneider Date: Wed, 4 Feb 2015 21:08:44 +0100 Subject: [PATCH] Implement standard Error trait for SqliteError --- src/lib.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index cb1a4f6..903793c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -57,6 +57,7 @@ extern crate libc; use std::mem; use std::ptr; use std::fmt; +use std::error; use std::rc::{Rc}; use std::cell::{RefCell, Cell}; use std::ffi::{CString}; @@ -100,8 +101,14 @@ pub struct SqliteError { } impl fmt::Display for SqliteError { - fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - write!(f, "SqliteError( code: {}, message: {} )", self.code, self.message) + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{} (SQLite error {})", self.message, self.code) + } +} + +impl error::Error for SqliteError { + fn description(&self) -> &str { + ffi::code_to_str(self.code) } }