Skip to content

Commit 7dcd41a

Browse files
committed
Fix for upstream changes
1 parent a75287e commit 7dcd41a

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

src/lib.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Postgres support for the `r2d2` connection pool.
22
#![doc(html_root_url="https://sfackler.github.io/doc")]
33
#![warn(missing_docs)]
4+
#![allow(unstable)]
45
extern crate r2d2;
56
extern crate postgres;
67
extern crate collect;
@@ -10,27 +11,25 @@ use std::borrow::ToOwned;
1011
use std::cell::RefCell;
1112
use std::default::Default;
1213
use std::error;
14+
use std::error::Error as _StdError;
1315
use std::fmt;
1416
use std::mem;
1517
use std::rc::Rc;
1618
use postgres::{IntoConnectParams, SslMode};
1719
use postgres::types::ToSql;
1820

1921
/// A unified enum of errors returned by postgres::Connection
20-
#[derive(Clone)]
22+
#[derive(Clone, Show)]
2123
pub enum Error {
2224
/// A postgres::ConnectError
2325
Connect(postgres::ConnectError),
2426
/// An postgres::Error
2527
Other(postgres::Error),
2628
}
2729

28-
impl fmt::Show for Error {
30+
impl fmt::String for Error {
2931
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
30-
match *self {
31-
Error::Connect(ref e) => write!(fmt, "{}", e),
32-
Error::Other(ref e) => write!(fmt, "{}", e),
33-
}
32+
write!(fmt, "{}", self.description())
3433
}
3534
}
3635

@@ -55,6 +54,7 @@ impl error::Error for Error {
5554
/// ## Example
5655
///
5756
/// ```rust,no_run
57+
/// #![allow(unstable)]
5858
/// extern crate r2d2;
5959
/// extern crate r2d2_postgres;
6060
/// extern crate postgres;
@@ -72,12 +72,12 @@ impl error::Error for Error {
7272
/// let error_handler = r2d2::LoggingErrorHandler;
7373
/// let pool = Arc::new(r2d2::Pool::new(config, manager, error_handler).unwrap());
7474
///
75-
/// for i in range(0, 10i32) {
75+
/// for i in 0..10i32 {
7676
/// let pool = pool.clone();
7777
/// Thread::spawn(move || {
7878
/// let conn = pool.get().unwrap();
7979
/// conn.execute("INSERT INTO foo (bar) VALUES ($1)", &[&i]).unwrap();
80-
/// }).detach();
80+
/// });
8181
/// }
8282
/// }
8383
/// ```
@@ -124,7 +124,7 @@ pub struct Config {
124124
/// The number of `postgres::Statement`s that will be internally cached.
125125
///
126126
/// Defaults to 10
127-
pub statement_pool_size: uint,
127+
pub statement_pool_size: u32,
128128
}
129129

130130
impl Default for Config {
@@ -157,10 +157,10 @@ impl StatementCachingManager {
157157

158158
impl r2d2::PoolManager<Connection, Error> for StatementCachingManager {
159159
fn connect(&self) -> Result<Connection, Error> {
160-
let cache = box RefCell::new(LruCache::<String, postgres::Statement<'static>>::new(
161-
self.config.statement_pool_size));
160+
let cache = Box::new(RefCell::new(LruCache::<String, postgres::Statement<'static>>::new(
161+
self.config.statement_pool_size as usize)));
162162
Ok(Connection {
163-
conn: box try!(self.manager.connect()),
163+
conn: Box::new(try!(self.manager.connect())),
164164
stmts: unsafe { mem::transmute(cache) },
165165
})
166166
}
@@ -181,7 +181,7 @@ pub trait GenericConnection {
181181
fn prepare<'a>(&'a self, query: &str) -> postgres::Result<Rc<postgres::Statement<'a>>>;
182182

183183
/// Like `postgres::Connection::execute`.
184-
fn execute(&self, query: &str, params: &[&ToSql]) -> postgres::Result<uint> {
184+
fn execute(&self, query: &str, params: &[&ToSql]) -> postgres::Result<usize> {
185185
self.prepare(query).and_then(|s| s.execute(params))
186186
}
187187

@@ -227,7 +227,7 @@ impl GenericConnection for Connection {
227227
return Ok(stmt.clone());
228228
}
229229

230-
let stmt = Rc::new(try!(self.conn.prepare(query[])));
230+
let stmt = Rc::new(try!(self.conn.prepare(&*query)));
231231
stmts.insert(query, stmt.clone());
232232
Ok(stmt)
233233
}
@@ -264,7 +264,7 @@ impl<'a> GenericConnection for Transaction<'a> {
264264
return Ok(stmt.clone());
265265
}
266266

267-
Ok(Rc::new(try!(self.trans.prepare(query[]))))
267+
Ok(Rc::new(try!(self.trans.prepare(&*query))))
268268
}
269269

270270
fn prepare_copy_in<'b>(&'b self, table: &str, columns: &[&str])

tests/test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(unstable)]
12
extern crate postgres;
23
extern crate r2d2;
34
extern crate r2d2_postgres;

0 commit comments

Comments
 (0)