@@ -25,7 +25,8 @@ impl Drop for InnerConnectionPool {
25
25
loop {
26
26
match self . pool . pop ( ) {
27
27
Some ( conn) => unsafe {
28
- drop ( cast:: transmute :: < * ( ) , ~PostgresConnection > ( conn) ) ;
28
+ let c: ~PostgresConnection = cast:: transmute ( conn) ;
29
+ drop ( c) ;
29
30
} ,
30
31
None => break
31
32
}
@@ -34,14 +35,9 @@ impl Drop for InnerConnectionPool {
34
35
}
35
36
36
37
impl InnerConnectionPool {
37
- fn new_connection ( & mut self ) -> Option < PostgresConnectError > {
38
- match PostgresConnection :: connect ( self . url , & self . ssl ) {
39
- Ok ( conn) => {
40
- unsafe { self . pool . push ( cast:: transmute ( ~conn) ) } ;
41
- None
42
- }
43
- Err ( err) => Some ( err)
44
- }
38
+ fn add_connection ( & mut self ) -> Result < ( ) , PostgresConnectError > {
39
+ PostgresConnection :: connect ( self . url , & self . ssl )
40
+ . map ( |c| unsafe { self . pool . push ( cast:: transmute ( ~c) ) ; } )
45
41
}
46
42
}
47
43
@@ -54,7 +50,7 @@ impl InnerConnectionPool {
54
50
/// ```rust,no_run
55
51
/// # use postgres::NoSsl;
56
52
/// # use postgres::pool::PostgresConnectionPool;
57
- /// let pool = PostgresConnectionPool::new("postgres://postgres@localhost",
53
+ /// let pool = PostgresConnectionPool::new(~ "postgres://postgres@localhost",
58
54
/// NoSsl, 5).unwrap();
59
55
/// for _ in range(0, 10) {
60
56
/// let pool = pool.clone();
@@ -74,19 +70,16 @@ impl PostgresConnectionPool {
74
70
///
75
71
/// Returns an error if the specified number of connections cannot be
76
72
/// created.
77
- pub fn new ( url : & str , ssl : SslMode , pool_size : uint )
73
+ pub fn new ( url : ~ str , ssl : SslMode , pool_size : uint )
78
74
-> Result < PostgresConnectionPool , PostgresConnectError > {
79
75
let mut pool = InnerConnectionPool {
80
- url : url. to_owned ( ) ,
76
+ url : url,
81
77
ssl : ssl,
82
78
pool : Vec :: new ( ) ,
83
79
} ;
84
80
85
81
for _ in range ( 0 , pool_size) {
86
- match pool. new_connection ( ) {
87
- None => ( ) ,
88
- Some ( err) => return Err ( err)
89
- }
82
+ try!( pool. add_connection ( ) ) ;
90
83
}
91
84
92
85
Ok ( PostgresConnectionPool {
0 commit comments