Skip to content

Commit 05398f2

Browse files
committed
Impl error::Error for Error
1 parent 2d5c9c5 commit 05398f2

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/lib.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ extern crate postgres;
66
use std::cell::RefCell;
77
use std::collections::LruCache;
88
use std::default::Default;
9+
use std::error;
910
use std::fmt;
1011
use std::mem;
1112
use std::rc::Rc;
@@ -26,6 +27,22 @@ impl fmt::Show for Error {
2627
}
2728
}
2829

30+
impl error::Error for Error {
31+
fn description(&self) -> &str {
32+
match *self {
33+
Error::Connect(_) => "Error opening a connection",
34+
Error::Other(_) => "Error communicating with server",
35+
}
36+
}
37+
38+
fn cause(&self) -> Option<&error::Error> {
39+
match *self {
40+
Error::Connect(ref err) => Some(err as &error::Error),
41+
Error::Other(ref err) => Some(err as &error::Error),
42+
}
43+
}
44+
}
45+
2946
pub struct PostgresPoolManager {
3047
params: Result<postgres::ConnectParams, postgres::ConnectError>,
3148
ssl_mode: SslMode,
@@ -153,7 +170,7 @@ impl GenericConnection for Connection {
153170
}
154171

155172
let stmt = Rc::new(try!(self.conn.prepare(query[])));
156-
stmts.put(query, stmt.clone());
173+
stmts.insert(query, stmt.clone());
157174
Ok(stmt)
158175
}
159176

0 commit comments

Comments
 (0)