Misc cleanup
This commit is contained in:
parent
e930dd8105
commit
9a7e5b7c7d
28
src/lib.rs
28
src/lib.rs
@ -221,10 +221,7 @@ impl IntoConnectParams for Url {
|
||||
..
|
||||
} = self;
|
||||
|
||||
let maybe_path = match url::decode_component(host.as_slice()) {
|
||||
Ok(path) => path,
|
||||
Err(err) => return Err(InvalidUrl(err)),
|
||||
};
|
||||
let maybe_path = try!(url::decode_component(host.as_slice()).map_err(InvalidUrl));
|
||||
let target = if maybe_path.as_slice().starts_with("/") {
|
||||
TargetUnix(Path::new(maybe_path))
|
||||
} else {
|
||||
@ -335,11 +332,7 @@ pub struct PostgresCancelData {
|
||||
pub fn cancel_query<T>(params: T, ssl: &SslMode, data: PostgresCancelData)
|
||||
-> Result<(), PostgresConnectError> where T: IntoConnectParams {
|
||||
let params = try!(params.into_connect_params());
|
||||
|
||||
let mut socket = match io::initialize_stream(¶ms, ssl) {
|
||||
Ok(socket) => socket,
|
||||
Err(err) => return Err(err)
|
||||
};
|
||||
let mut socket = try!(io::initialize_stream(¶ms, ssl));
|
||||
|
||||
try_pg_conn!(socket.write_message(&CancelRequest {
|
||||
code: message::CANCEL_CODE,
|
||||
@ -536,7 +529,7 @@ impl InnerPostgresConnection {
|
||||
param_types: []
|
||||
},
|
||||
Describe {
|
||||
variant: 'S' as u8,
|
||||
variant: b'S',
|
||||
name: stmt_name.as_slice(),
|
||||
},
|
||||
Sync]));
|
||||
@ -559,8 +552,7 @@ impl InnerPostgresConnection {
|
||||
|
||||
let mut result_desc: Vec<ResultDescription> = match try_pg!(self.read_message()) {
|
||||
RowDescription { descriptions } => {
|
||||
descriptions.move_iter().map(|desc| {
|
||||
let RowDescriptionEntry { name, type_oid, .. } = desc;
|
||||
descriptions.move_iter().map(|RowDescriptionEntry { name, type_oid, .. }| {
|
||||
ResultDescription {
|
||||
name: name,
|
||||
ty: PostgresType::from_oid(type_oid)
|
||||
@ -587,8 +579,8 @@ impl InnerPostgresConnection {
|
||||
})
|
||||
}
|
||||
|
||||
fn set_type_names<'a, I: Iterator<&'a mut PostgresType>>(&mut self, mut it: I)
|
||||
-> PostgresResult<()> {
|
||||
fn set_type_names<'a, I>(&mut self, mut it: I) -> PostgresResult<()>
|
||||
where I: Iterator<&'a mut PostgresType> {
|
||||
for ty in it {
|
||||
match *ty {
|
||||
PgUnknownType { oid, ref mut name } => *name = try!(self.get_type_name(oid)),
|
||||
@ -734,9 +726,7 @@ impl PostgresConnection {
|
||||
///
|
||||
/// Use the `LISTEN` command to register this connection for notifications.
|
||||
pub fn notifications<'a>(&'a self) -> PostgresNotifications<'a> {
|
||||
PostgresNotifications {
|
||||
conn: self
|
||||
}
|
||||
PostgresNotifications { conn: self }
|
||||
}
|
||||
|
||||
/// Creates a new prepared statement.
|
||||
@ -1067,7 +1057,7 @@ impl<'conn> PostgresStatement<'conn> {
|
||||
check_desync!(self.conn);
|
||||
try_pg!(self.conn.write_messages([
|
||||
Close {
|
||||
variant: 'S' as u8,
|
||||
variant: b'S',
|
||||
name: self.name.as_slice()
|
||||
},
|
||||
Sync]));
|
||||
@ -1275,7 +1265,7 @@ impl<'stmt> PostgresRows<'stmt> {
|
||||
check_desync!(self.stmt.conn);
|
||||
try_pg!(self.stmt.conn.write_messages([
|
||||
Close {
|
||||
variant: 'P' as u8,
|
||||
variant: b'P',
|
||||
name: self.name.as_slice()
|
||||
},
|
||||
Sync]));
|
||||
|
@ -140,7 +140,7 @@ impl<W: Writer> WriteMessage for W {
|
||||
|
||||
match *message {
|
||||
Bind { portal, statement, formats, values, result_formats } => {
|
||||
ident = Some('B');
|
||||
ident = Some(b'B');
|
||||
try!(buf.write_cstr(portal));
|
||||
try!(buf.write_cstr(statement));
|
||||
|
||||
@ -173,22 +173,22 @@ impl<W: Writer> WriteMessage for W {
|
||||
try!(buf.write_be_u32(secret_key));
|
||||
}
|
||||
Close { variant, name } => {
|
||||
ident = Some('C');
|
||||
ident = Some(b'C');
|
||||
try!(buf.write_u8(variant));
|
||||
try!(buf.write_cstr(name));
|
||||
}
|
||||
Describe { variant, name } => {
|
||||
ident = Some('D');
|
||||
ident = Some(b'D');
|
||||
try!(buf.write_u8(variant));
|
||||
try!(buf.write_cstr(name));
|
||||
}
|
||||
Execute { portal, max_rows } => {
|
||||
ident = Some('E');
|
||||
ident = Some(b'E');
|
||||
try!(buf.write_cstr(portal));
|
||||
try!(buf.write_be_i32(max_rows));
|
||||
}
|
||||
Parse { name, query, param_types } => {
|
||||
ident = Some('P');
|
||||
ident = Some(b'P');
|
||||
try!(buf.write_cstr(name));
|
||||
try!(buf.write_cstr(query));
|
||||
try!(buf.write_be_i16(param_types.len() as i16));
|
||||
@ -197,11 +197,11 @@ impl<W: Writer> WriteMessage for W {
|
||||
}
|
||||
}
|
||||
PasswordMessage { password } => {
|
||||
ident = Some('p');
|
||||
ident = Some(b'p');
|
||||
try!(buf.write_cstr(password));
|
||||
}
|
||||
Query { query } => {
|
||||
ident = Some('Q');
|
||||
ident = Some(b'Q');
|
||||
try!(buf.write_cstr(query));
|
||||
}
|
||||
StartupMessage { version, parameters } => {
|
||||
@ -214,15 +214,15 @@ impl<W: Writer> WriteMessage for W {
|
||||
}
|
||||
SslRequest { code } => try!(buf.write_be_u32(code)),
|
||||
Sync => {
|
||||
ident = Some('S');
|
||||
ident = Some(b'S');
|
||||
}
|
||||
Terminate => {
|
||||
ident = Some('X');
|
||||
ident = Some(b'X');
|
||||
}
|
||||
}
|
||||
|
||||
match ident {
|
||||
Some(ident) => try!(self.write_u8(ident as u8)),
|
||||
Some(ident) => try!(self.write_u8(ident)),
|
||||
None => ()
|
||||
}
|
||||
|
||||
@ -264,34 +264,34 @@ impl<R: Reader> ReadMessage for R {
|
||||
let len = try!(self.read_be_u32()) as uint - mem::size_of::<i32>();
|
||||
let mut buf = MemReader::new(try!(self.read_exact(len)));
|
||||
|
||||
let ret = match ident as char {
|
||||
'1' => ParseComplete,
|
||||
'2' => BindComplete,
|
||||
'3' => CloseComplete,
|
||||
'A' => NotificationResponse {
|
||||
let ret = match ident {
|
||||
b'1' => ParseComplete,
|
||||
b'2' => BindComplete,
|
||||
b'3' => CloseComplete,
|
||||
b'A' => NotificationResponse {
|
||||
pid: try!(buf.read_be_u32()),
|
||||
channel: try!(buf.read_cstr()),
|
||||
payload: try!(buf.read_cstr())
|
||||
},
|
||||
'C' => CommandComplete { tag: try!(buf.read_cstr()) },
|
||||
'D' => try!(read_data_row(&mut buf)),
|
||||
'E' => ErrorResponse { fields: try!(read_fields(&mut buf)) },
|
||||
'I' => EmptyQueryResponse,
|
||||
'K' => BackendKeyData {
|
||||
b'C' => CommandComplete { tag: try!(buf.read_cstr()) },
|
||||
b'D' => try!(read_data_row(&mut buf)),
|
||||
b'E' => ErrorResponse { fields: try!(read_fields(&mut buf)) },
|
||||
b'I' => EmptyQueryResponse,
|
||||
b'K' => BackendKeyData {
|
||||
process_id: try!(buf.read_be_u32()),
|
||||
secret_key: try!(buf.read_be_u32())
|
||||
},
|
||||
'n' => NoData,
|
||||
'N' => NoticeResponse { fields: try!(read_fields(&mut buf)) },
|
||||
'R' => try!(read_auth_message(&mut buf)),
|
||||
's' => PortalSuspended,
|
||||
'S' => ParameterStatus {
|
||||
b'n' => NoData,
|
||||
b'N' => NoticeResponse { fields: try!(read_fields(&mut buf)) },
|
||||
b'R' => try!(read_auth_message(&mut buf)),
|
||||
b's' => PortalSuspended,
|
||||
b'S' => ParameterStatus {
|
||||
parameter: try!(buf.read_cstr()),
|
||||
value: try!(buf.read_cstr())
|
||||
},
|
||||
't' => try!(read_parameter_description(&mut buf)),
|
||||
'T' => try!(read_row_description(&mut buf)),
|
||||
'Z' => ReadyForQuery { _state: try!(buf.read_u8()) },
|
||||
b't' => try!(read_parameter_description(&mut buf)),
|
||||
b'T' => try!(read_row_description(&mut buf)),
|
||||
b'Z' => ReadyForQuery { _state: try!(buf.read_u8()) },
|
||||
ident => return Err(IoError {
|
||||
kind: OtherIoError,
|
||||
desc: "Unexpected message tag",
|
||||
@ -337,7 +337,7 @@ fn read_auth_message(buf: &mut MemReader) -> IoResult<BackendMessage> {
|
||||
2 => AuthenticationKerberosV5,
|
||||
3 => AuthenticationCleartextPassword,
|
||||
5 => {
|
||||
let mut salt = [0, 0, 0, 0];
|
||||
let mut salt = [0, ..4];
|
||||
try!(buf.read_at_least(salt.len(), salt));
|
||||
AuthenticationMD5Password { salt: salt }
|
||||
},
|
||||
|
@ -4,7 +4,7 @@ use std::mem;
|
||||
use std::slice;
|
||||
|
||||
/// Information about a dimension of an array
|
||||
#[deriving(PartialEq, Eq, Clone, Show)]
|
||||
#[deriving(PartialEq, Eq, Clone)]
|
||||
pub struct DimensionInfo {
|
||||
/// The size of the dimension
|
||||
pub len: uint,
|
||||
|
Loading…
Reference in New Issue
Block a user