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) ]
45extern crate r2d2;
56extern crate postgres;
67extern crate collect;
@@ -10,27 +11,25 @@ use std::borrow::ToOwned;
1011use std:: cell:: RefCell ;
1112use std:: default:: Default ;
1213use std:: error;
14+ use std:: error:: Error as _StdError;
1315use std:: fmt;
1416use std:: mem;
1517use std:: rc:: Rc ;
1618use postgres:: { IntoConnectParams , SslMode } ;
1719use postgres:: types:: ToSql ;
1820
1921/// A unified enum of errors returned by postgres::Connection
20- #[ derive( Clone ) ]
22+ #[ derive( Clone , Show ) ]
2123pub 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
130130impl Default for Config {
@@ -157,10 +157,10 @@ impl StatementCachingManager {
157157
158158impl 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 ] )
0 commit comments