diff --git a/src/lib.rs b/src/lib.rs index 6294d0da..5248c86a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -70,12 +70,12 @@ extern crate serialize; extern crate sync; extern crate time; extern crate phf; +#[phase(syntax)] +extern crate phf_mac; extern crate url; #[phase(syntax, link)] extern crate log; extern crate uuid; -#[phase(syntax)] -extern crate phf_mac; use collections::{Deque, HashMap, RingBuf}; use url::{UserInfo, Url}; diff --git a/src/pool.rs b/src/pool.rs index 193d4c57..7e2a7941 100644 --- a/src/pool.rs +++ b/src/pool.rs @@ -1,6 +1,5 @@ //! A simple connection pool -use std::cast; use sync::{Arc, Mutex}; use {PostgresNotifications, @@ -18,28 +17,13 @@ use types::ToSql; struct InnerConnectionPool { params: PostgresConnectParams, ssl: SslMode, - // Actually Vec<~PostgresConnection> - pool: Vec<*()>, -} - -impl Drop for InnerConnectionPool { - fn drop(&mut self) { - loop { - match self.pool.pop() { - Some(conn) => unsafe { - let c: ~PostgresConnection = cast::transmute(conn); - drop(c); - }, - None => break - } - } - } + pool: Vec, } impl InnerConnectionPool { fn add_connection(&mut self) -> Result<(), PostgresConnectError> { PostgresConnection::connect(self.params.clone(), &self.ssl) - .map(|c| unsafe { self.pool.push(cast::transmute(~c)); }) + .map(|c| self.pool.push(c)) } } @@ -101,7 +85,7 @@ impl PostgresConnectionPool { PooledPostgresConnection { pool: self.clone(), - conn: Some(unsafe { cast::transmute(pool.pool.pop().unwrap()) }) + conn: Some(pool.pool.pop().unwrap()) } } } @@ -113,14 +97,13 @@ impl PostgresConnectionPool { pub struct PooledPostgresConnection { pool: PostgresConnectionPool, // TODO remove the Option wrapper when drop takes self by value - conn: Option<~PostgresConnection> + conn: Option } impl Drop for PooledPostgresConnection { fn drop(&mut self) { - let conn = unsafe { cast::transmute(self.conn.take_unwrap()) }; let mut pool = self.pool.pool.lock(); - pool.pool.push(conn); + pool.pool.push(self.conn.take_unwrap()); pool.cond.signal(); } }