Skip to content

Commit 3b93302

Browse files
committed
Change cancel_query to return a Result
1 parent 20904ab commit 3b93302

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

lib.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,10 @@ pub struct PostgresCancelData {
208208
/// `PostgresConnection::cancel_data`. The object can cancel any query made on
209209
/// that connection.
210210
pub fn cancel_query(url: &str, ssl: &SslMode, data: PostgresCancelData)
211-
-> Option<PostgresConnectError> {
211+
-> Result<(), PostgresConnectError> {
212212
let Url { host, port, .. }: Url = match FromStr::from_str(url) {
213213
Some(url) => url,
214-
None => return Some(InvalidUrl)
214+
None => return Err(InvalidUrl)
215215
};
216216
let port = match port {
217217
Some(port) => FromStr::from_str(port).unwrap(),
@@ -220,7 +220,7 @@ pub fn cancel_query(url: &str, ssl: &SslMode, data: PostgresCancelData)
220220

221221
let mut socket = match initialize_stream(host, port, ssl) {
222222
Ok(socket) => socket,
223-
Err(err) => return Some(err)
223+
Err(err) => return Err(err)
224224
};
225225

226226
socket.write_message(&CancelRequest {
@@ -230,7 +230,7 @@ pub fn cancel_query(url: &str, ssl: &SslMode, data: PostgresCancelData)
230230
});
231231
socket.flush();
232232

233-
None
233+
Ok(())
234234
}
235235

236236
fn open_socket(host: &str, port: Port)
@@ -325,7 +325,7 @@ impl Writer for InternalStream {
325325

326326
struct InnerPostgresConnection {
327327
stream: BufferedStream<InternalStream>,
328-
next_stmt_id: int,
328+
next_stmt_id: uint,
329329
notice_handler: ~PostgresNoticeHandler,
330330
notifications: RingBuf<PostgresNotification>,
331331
cancel_data: PostgresCancelData,
@@ -347,7 +347,7 @@ impl InnerPostgresConnection {
347347
host,
348348
port,
349349
user,
350-
path,
350+
path: mut path,
351351
query: mut args,
352352
..
353353
}: Url = match FromStr::from_str(url) {
@@ -387,7 +387,8 @@ impl InnerPostgresConnection {
387387
args.push((~"user", user.user.clone()));
388388
if !path.is_empty() {
389389
// path contains the leading /
390-
args.push((~"database", path.slice_from(1).to_owned()));
390+
path.shift_char();
391+
args.push((~"database", path));
391392
}
392393
conn.write_messages([StartupMessage {
393394
version: message::PROTOCOL_VERSION,

test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ fn test_cancel_query() {
615615
do spawn {
616616
timer::sleep(500);
617617
assert!(lib::cancel_query("postgres://postgres@localhost", &NoSsl,
618-
cancel_data).is_none());
618+
cancel_data).is_ok());
619619
}
620620

621621
match conn.try_update("SELECT pg_sleep(10)", []) {

0 commit comments

Comments
 (0)