Skip to content

Commit 9a7e5b7

Browse files
committed
Misc cleanup
1 parent e930dd8 commit 9a7e5b7

3 files changed

Lines changed: 39 additions & 49 deletions

File tree

src/lib.rs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,7 @@ impl IntoConnectParams for Url {
221221
..
222222
} = self;
223223

224-
let maybe_path = match url::decode_component(host.as_slice()) {
225-
Ok(path) => path,
226-
Err(err) => return Err(InvalidUrl(err)),
227-
};
224+
let maybe_path = try!(url::decode_component(host.as_slice()).map_err(InvalidUrl));
228225
let target = if maybe_path.as_slice().starts_with("/") {
229226
TargetUnix(Path::new(maybe_path))
230227
} else {
@@ -335,11 +332,7 @@ pub struct PostgresCancelData {
335332
pub fn cancel_query<T>(params: T, ssl: &SslMode, data: PostgresCancelData)
336333
-> Result<(), PostgresConnectError> where T: IntoConnectParams {
337334
let params = try!(params.into_connect_params());
338-
339-
let mut socket = match io::initialize_stream(&params, ssl) {
340-
Ok(socket) => socket,
341-
Err(err) => return Err(err)
342-
};
335+
let mut socket = try!(io::initialize_stream(&params, ssl));
343336

344337
try_pg_conn!(socket.write_message(&CancelRequest {
345338
code: message::CANCEL_CODE,
@@ -536,7 +529,7 @@ impl InnerPostgresConnection {
536529
param_types: []
537530
},
538531
Describe {
539-
variant: 'S' as u8,
532+
variant: b'S',
540533
name: stmt_name.as_slice(),
541534
},
542535
Sync]));
@@ -559,8 +552,7 @@ impl InnerPostgresConnection {
559552

560553
let mut result_desc: Vec<ResultDescription> = match try_pg!(self.read_message()) {
561554
RowDescription { descriptions } => {
562-
descriptions.move_iter().map(|desc| {
563-
let RowDescriptionEntry { name, type_oid, .. } = desc;
555+
descriptions.move_iter().map(|RowDescriptionEntry { name, type_oid, .. }| {
564556
ResultDescription {
565557
name: name,
566558
ty: PostgresType::from_oid(type_oid)
@@ -587,8 +579,8 @@ impl InnerPostgresConnection {
587579
})
588580
}
589581

590-
fn set_type_names<'a, I: Iterator<&'a mut PostgresType>>(&mut self, mut it: I)
591-
-> PostgresResult<()> {
582+
fn set_type_names<'a, I>(&mut self, mut it: I) -> PostgresResult<()>
583+
where I: Iterator<&'a mut PostgresType> {
592584
for ty in it {
593585
match *ty {
594586
PgUnknownType { oid, ref mut name } => *name = try!(self.get_type_name(oid)),
@@ -734,9 +726,7 @@ impl PostgresConnection {
734726
///
735727
/// Use the `LISTEN` command to register this connection for notifications.
736728
pub fn notifications<'a>(&'a self) -> PostgresNotifications<'a> {
737-
PostgresNotifications {
738-
conn: self
739-
}
729+
PostgresNotifications { conn: self }
740730
}
741731

742732
/// Creates a new prepared statement.
@@ -1067,7 +1057,7 @@ impl<'conn> PostgresStatement<'conn> {
10671057
check_desync!(self.conn);
10681058
try_pg!(self.conn.write_messages([
10691059
Close {
1070-
variant: 'S' as u8,
1060+
variant: b'S',
10711061
name: self.name.as_slice()
10721062
},
10731063
Sync]));
@@ -1275,7 +1265,7 @@ impl<'stmt> PostgresRows<'stmt> {
12751265
check_desync!(self.stmt.conn);
12761266
try_pg!(self.stmt.conn.write_messages([
12771267
Close {
1278-
variant: 'P' as u8,
1268+
variant: b'P',
12791269
name: self.name.as_slice()
12801270
},
12811271
Sync]));

src/message.rs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl<W: Writer> WriteMessage for W {
140140

141141
match *message {
142142
Bind { portal, statement, formats, values, result_formats } => {
143-
ident = Some('B');
143+
ident = Some(b'B');
144144
try!(buf.write_cstr(portal));
145145
try!(buf.write_cstr(statement));
146146

@@ -173,22 +173,22 @@ impl<W: Writer> WriteMessage for W {
173173
try!(buf.write_be_u32(secret_key));
174174
}
175175
Close { variant, name } => {
176-
ident = Some('C');
176+
ident = Some(b'C');
177177
try!(buf.write_u8(variant));
178178
try!(buf.write_cstr(name));
179179
}
180180
Describe { variant, name } => {
181-
ident = Some('D');
181+
ident = Some(b'D');
182182
try!(buf.write_u8(variant));
183183
try!(buf.write_cstr(name));
184184
}
185185
Execute { portal, max_rows } => {
186-
ident = Some('E');
186+
ident = Some(b'E');
187187
try!(buf.write_cstr(portal));
188188
try!(buf.write_be_i32(max_rows));
189189
}
190190
Parse { name, query, param_types } => {
191-
ident = Some('P');
191+
ident = Some(b'P');
192192
try!(buf.write_cstr(name));
193193
try!(buf.write_cstr(query));
194194
try!(buf.write_be_i16(param_types.len() as i16));
@@ -197,11 +197,11 @@ impl<W: Writer> WriteMessage for W {
197197
}
198198
}
199199
PasswordMessage { password } => {
200-
ident = Some('p');
200+
ident = Some(b'p');
201201
try!(buf.write_cstr(password));
202202
}
203203
Query { query } => {
204-
ident = Some('Q');
204+
ident = Some(b'Q');
205205
try!(buf.write_cstr(query));
206206
}
207207
StartupMessage { version, parameters } => {
@@ -214,15 +214,15 @@ impl<W: Writer> WriteMessage for W {
214214
}
215215
SslRequest { code } => try!(buf.write_be_u32(code)),
216216
Sync => {
217-
ident = Some('S');
217+
ident = Some(b'S');
218218
}
219219
Terminate => {
220-
ident = Some('X');
220+
ident = Some(b'X');
221221
}
222222
}
223223

224224
match ident {
225-
Some(ident) => try!(self.write_u8(ident as u8)),
225+
Some(ident) => try!(self.write_u8(ident)),
226226
None => ()
227227
}
228228

@@ -264,34 +264,34 @@ impl<R: Reader> ReadMessage for R {
264264
let len = try!(self.read_be_u32()) as uint - mem::size_of::<i32>();
265265
let mut buf = MemReader::new(try!(self.read_exact(len)));
266266

267-
let ret = match ident as char {
268-
'1' => ParseComplete,
269-
'2' => BindComplete,
270-
'3' => CloseComplete,
271-
'A' => NotificationResponse {
267+
let ret = match ident {
268+
b'1' => ParseComplete,
269+
b'2' => BindComplete,
270+
b'3' => CloseComplete,
271+
b'A' => NotificationResponse {
272272
pid: try!(buf.read_be_u32()),
273273
channel: try!(buf.read_cstr()),
274274
payload: try!(buf.read_cstr())
275275
},
276-
'C' => CommandComplete { tag: try!(buf.read_cstr()) },
277-
'D' => try!(read_data_row(&mut buf)),
278-
'E' => ErrorResponse { fields: try!(read_fields(&mut buf)) },
279-
'I' => EmptyQueryResponse,
280-
'K' => BackendKeyData {
276+
b'C' => CommandComplete { tag: try!(buf.read_cstr()) },
277+
b'D' => try!(read_data_row(&mut buf)),
278+
b'E' => ErrorResponse { fields: try!(read_fields(&mut buf)) },
279+
b'I' => EmptyQueryResponse,
280+
b'K' => BackendKeyData {
281281
process_id: try!(buf.read_be_u32()),
282282
secret_key: try!(buf.read_be_u32())
283283
},
284-
'n' => NoData,
285-
'N' => NoticeResponse { fields: try!(read_fields(&mut buf)) },
286-
'R' => try!(read_auth_message(&mut buf)),
287-
's' => PortalSuspended,
288-
'S' => ParameterStatus {
284+
b'n' => NoData,
285+
b'N' => NoticeResponse { fields: try!(read_fields(&mut buf)) },
286+
b'R' => try!(read_auth_message(&mut buf)),
287+
b's' => PortalSuspended,
288+
b'S' => ParameterStatus {
289289
parameter: try!(buf.read_cstr()),
290290
value: try!(buf.read_cstr())
291291
},
292-
't' => try!(read_parameter_description(&mut buf)),
293-
'T' => try!(read_row_description(&mut buf)),
294-
'Z' => ReadyForQuery { _state: try!(buf.read_u8()) },
292+
b't' => try!(read_parameter_description(&mut buf)),
293+
b'T' => try!(read_row_description(&mut buf)),
294+
b'Z' => ReadyForQuery { _state: try!(buf.read_u8()) },
295295
ident => return Err(IoError {
296296
kind: OtherIoError,
297297
desc: "Unexpected message tag",
@@ -337,7 +337,7 @@ fn read_auth_message(buf: &mut MemReader) -> IoResult<BackendMessage> {
337337
2 => AuthenticationKerberosV5,
338338
3 => AuthenticationCleartextPassword,
339339
5 => {
340-
let mut salt = [0, 0, 0, 0];
340+
let mut salt = [0, ..4];
341341
try!(buf.read_at_least(salt.len(), salt));
342342
AuthenticationMD5Password { salt: salt }
343343
},

src/types/array.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::mem;
44
use std::slice;
55

66
/// Information about a dimension of an array
7-
#[deriving(PartialEq, Eq, Clone, Show)]
7+
#[deriving(PartialEq, Eq, Clone)]
88
pub struct DimensionInfo {
99
/// The size of the dimension
1010
pub len: uint,

0 commit comments

Comments
 (0)