Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit42ce9bb

Browse files
committed
Update to postgres 0.15
1 parentd634304 commit42ce9bb

File tree

2 files changed

+13
-46
lines changed

2 files changed

+13
-46
lines changed

‎Cargo.toml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ path = "tests/test.rs"
1919

2020
[dependencies]
2121
r2d2 ="0.7"
22-
postgres ="0.14"
22+
postgres ="0.15"
23+
postgres-shared ="0.4"

‎src/lib.rs‎

Lines changed: 11 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
#![warn(missing_docs)]
44
pubexterncrate r2d2;
55
pubexterncrate postgres;
6+
externcrate postgres_shared;
67

7-
use std::error;
8-
use std::error::Erroras _StdError;
9-
use std::fmt;
8+
use postgres::{Connection,Error,Result};
109
use postgres::params::{ConnectParams,IntoConnectParams};
1110
use postgres::tls::TlsHandshake;
1211

@@ -21,37 +20,6 @@ pub enum TlsMode {
2120
Require(Box<TlsHandshake +Sync +Send>),
2221
}
2322

24-
/// A unified enum of errors returned by postgres::Connection
25-
#[derive(Debug)]
26-
pubenumError{
27-
/// A postgres::error::ConnectError
28-
Connect(postgres::error::ConnectError),
29-
/// An postgres::error::Error
30-
Other(postgres::error::Error),
31-
}
32-
33-
impl fmt::DisplayforError{
34-
fnfmt(&self,fmt:&mut fmt::Formatter) -> fmt::Result{
35-
write!(fmt,"{}: {}",self.description(),self.cause().unwrap())
36-
}
37-
}
38-
39-
impl error::ErrorforError{
40-
fndescription(&self) ->&str{
41-
match*self{
42-
Error::Connect(_) =>"Error opening a connection",
43-
Error::Other(_) =>"Error communicating with server",
44-
}
45-
}
46-
47-
fncause(&self) ->Option<&error::Error>{
48-
match*self{
49-
Error::Connect(ref err) =>Some(erras&error::Error),
50-
Error::Other(ref err) =>Some(erras&error::Error),
51-
}
52-
}
53-
}
54-
5523
/// An `r2d2::ManageConnection` for `postgres::Connection`s.
5624
///
5725
/// ## Example
@@ -92,13 +60,11 @@ impl PostgresConnectionManager {
9260
/// types.
9361
pubfnnew<T>(params:T,
9462
ssl_mode:TlsMode)
95-
->Result<PostgresConnectionManager, postgres::error::ConnectError>
63+
->Result<PostgresConnectionManager>
9664
whereT:IntoConnectParams
9765
{
98-
let params =match params.into_connect_params(){
99-
Ok(params) => params,
100-
Err(err) =>returnErr(postgres::error::ConnectError::ConnectParams(err)),
101-
};
66+
// fixme we shouldn't be using this private constructor :(
67+
let params = params.into_connect_params().map_err(postgres_shared::error::connect)?;
10268

10369
Ok(PostgresConnectionManager{
10470
params: params,
@@ -108,23 +74,23 @@ impl PostgresConnectionManager {
10874
}
10975

11076
impl r2d2::ManageConnectionforPostgresConnectionManager{
111-
typeConnection =postgres::Connection;
77+
typeConnection =Connection;
11278
typeError =Error;
11379

114-
fnconnect(&self) ->Result<postgres::Connection,Error>{
80+
fnconnect(&self) ->Result<postgres::Connection>{
11581
let mode =matchself.ssl_mode{
11682
TlsMode::None => postgres::TlsMode::None,
11783
TlsMode::Prefer(ref n) => postgres::TlsMode::Prefer(&**n),
11884
TlsMode::Require(ref n) => postgres::TlsMode::Require(&**n),
11985
};
120-
postgres::Connection::connect(self.params.clone(), mode).map_err(Error::Connect)
86+
postgres::Connection::connect(self.params.clone(), mode)
12187
}
12288

123-
fnis_valid(&self,conn:&mutpostgres::Connection) ->Result<(),Error>{
124-
conn.batch_execute("").map_err(Error::Other)
89+
fnis_valid(&self,conn:&mutConnection) ->Result<()>{
90+
conn.batch_execute("")
12591
}
12692

127-
fnhas_broken(&self,conn:&mutpostgres::Connection) ->bool{
93+
fnhas_broken(&self,conn:&mutConnection) ->bool{
12894
conn.is_desynchronized()
12995
}
13096
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp