Skip to content

Commit 16424dd

Browse files
committed
Random cleanup
1 parent 7d3b250 commit 16424dd

File tree

4 files changed

+69
-71
lines changed

4 files changed

+69
-71
lines changed

src/error.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,27 @@ use types::Type;
1313

1414
include!(concat!(env!("OUT_DIR"), "/sqlstate.rs"));
1515

16-
/// Reasons a new Postgres connection could fail
16+
/// Reasons a new Postgres connection could fail.
1717
#[derive(Debug)]
1818
pub enum ConnectError {
19-
/// The provided URL could not be parsed
19+
/// The provided URL could not be parsed.
2020
InvalidUrl(String),
21-
/// The URL was missing a user
21+
/// The URL was missing a user.
2222
MissingUser,
23-
/// An error from the Postgres server itself
23+
/// An error from the Postgres server itself.
2424
DbError(DbError),
25-
/// A password was required but not provided in the URL
25+
/// A password was required but not provided in the URL.
2626
MissingPassword,
2727
/// The Postgres server requested an authentication method not supported
28-
/// by the driver
28+
/// by the driver.
2929
UnsupportedAuthentication,
30-
/// The Postgres server does not support SSL encryption
30+
/// The Postgres server does not support SSL encryption.
3131
NoSslSupport,
32-
/// There was an error initializing the SSL session
32+
/// There was an error initializing the SSL session.
3333
SslError(SslError),
34-
/// There was an error communicating with the server
34+
/// There was an error communicating with the server.
3535
IoError(io::Error),
36-
/// The server sent an unexpected response
36+
/// The server sent an unexpected response.
3737
BadResponse,
3838
}
3939

@@ -98,38 +98,38 @@ impl From<byteorder::Error> for ConnectError {
9898
}
9999
}
100100

101-
/// Represents the position of an error in a query
101+
/// Represents the position of an error in a query.
102102
#[derive(Clone, PartialEq, Eq, Debug)]
103103
pub enum ErrorPosition {
104-
/// A position in the original query
104+
/// A position in the original query.
105105
Normal(u32),
106-
/// A position in an internally generated query
106+
/// A position in an internally generated query.
107107
Internal {
108-
/// The byte position
108+
/// The byte position.
109109
position: u32,
110-
/// A query generated by the Postgres server
110+
/// A query generated by the Postgres server.
111111
query: String
112112
}
113113
}
114114

115-
/// An error encountered when communicating with the Postgres server
115+
/// An error encountered when communicating with the Postgres server.
116116
#[derive(Debug)]
117117
pub enum Error {
118-
/// An error reported by the Postgres server
118+
/// An error reported by the Postgres server.
119119
DbError(DbError),
120-
/// An error communicating with the Postgres server
120+
/// An error communicating with the Postgres server.
121121
IoError(io::Error),
122122
/// The communication channel with the Postgres server has desynchronized
123123
/// due to an earlier communications error.
124124
StreamDesynchronized,
125125
/// An attempt was made to convert between incompatible Rust and Postgres
126-
/// types
126+
/// types.
127127
WrongType(Type),
128-
/// An attempt was made to read from a column that does not exist
128+
/// An attempt was made to read from a column that does not exist.
129129
InvalidColumn,
130-
/// A value was NULL but converted to a non-nullable Rust type
130+
/// A value was NULL but converted to a non-nullable Rust type.
131131
WasNull,
132-
/// The server returned an unexpected response
132+
/// The server returned an unexpected response.
133133
BadResponse,
134134
}
135135

src/lib.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -232,18 +232,18 @@ impl HandleNotice for LoggingNoticeHandler {
232232
}
233233
}
234234

235-
/// An asynchronous notification
235+
/// An asynchronous notification.
236236
#[derive(Clone, Debug)]
237237
pub struct Notification {
238-
/// The process ID of the notifying backend process
238+
/// The process ID of the notifying backend process.
239239
pub pid: u32,
240-
/// The name of the channel that the notify has been raised on
240+
/// The name of the channel that the notify has been raised on.
241241
pub channel: String,
242-
/// The "payload" string passed from the notifying process
242+
/// The "payload" string passed from the notifying process.
243243
pub payload: String,
244244
}
245245

246-
/// An iterator over asynchronous notifications
246+
/// An iterator over asynchronous notifications.
247247
pub struct Notifications<'conn> {
248248
conn: &'conn Connection
249249
}
@@ -350,12 +350,12 @@ impl<'conn> Notifications<'conn> {
350350
*/
351351
}
352352

353-
/// Contains information necessary to cancel queries for a session
353+
/// Contains information necessary to cancel queries for a session.
354354
#[derive(Copy, Clone, Debug)]
355355
pub struct CancelData {
356-
/// The process ID of the session
356+
/// The process ID of the session.
357357
pub process_id: u32,
358-
/// The secret key for the session
358+
/// The secret key for the session.
359359
pub secret_key: u32,
360360
}
361361

@@ -1246,14 +1246,14 @@ impl Connection {
12461246
}
12471247
}
12481248

1249-
/// Specifies the SSL support requested for a new connection
1249+
/// Specifies the SSL support requested for a new connection.
12501250
#[derive(Debug)]
12511251
pub enum SslMode {
1252-
/// The connection will not use SSL
1252+
/// The connection will not use SSL.
12531253
None,
1254-
/// The connection will use SSL if the backend supports it
1254+
/// The connection will use SSL if the backend supports it.
12551255
Prefer(SslContext),
1256-
/// The connection must use SSL
1256+
/// The connection must use SSL.
12571257
Require(SslContext)
12581258
}
12591259

@@ -1387,7 +1387,7 @@ impl<'conn> Transaction<'conn> {
13871387
}
13881388
}
13891389

1390-
/// A prepared statement
1390+
/// A prepared statement.
13911391
pub struct Statement<'conn> {
13921392
conn: &'conn Connection,
13931393
name: String,
@@ -1833,7 +1833,7 @@ impl<'a> fmt::Debug for Row<'a> {
18331833
}
18341834

18351835
impl<'a> Row<'a> {
1836-
/// Returns the number of values in the row
1836+
/// Returns the number of values in the row.
18371837
pub fn len(&self) -> usize {
18381838
self.data.len()
18391839
}
@@ -1925,7 +1925,7 @@ impl<'a> RowIndex for &'a str {
19251925
}
19261926
}
19271927

1928-
/// A lazily-loaded iterator over the resulting rows of a query
1928+
/// A lazily-loaded iterator over the resulting rows of a query.
19291929
pub struct LazyRows<'trans, 'stmt> {
19301930
stmt: &'stmt Statement<'stmt>,
19311931
data: VecDeque<Vec<Option<Vec<u8>>>>,
@@ -2017,7 +2017,7 @@ impl<'trans, 'stmt> Iterator for LazyRows<'trans, 'stmt> {
20172017
}
20182018
}
20192019

2020-
/// A prepared COPY FROM STDIN statement
2020+
/// A prepared `COPY FROM STDIN` statement.
20212021
pub struct CopyInStatement<'a> {
20222022
conn: &'a Connection,
20232023
name: String,

src/types/mod.rs

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ mod rustc_serialize;
5252
#[cfg(feature = "serde")]
5353
mod serde;
5454

55-
/// A Postgres OID
55+
/// A Postgres OID.
5656
pub type Oid = u32;
5757

5858
/// Represents the kind of a Postgres type.
@@ -76,14 +76,14 @@ macro_rules! as_expr {
7676

7777
macro_rules! make_postgres_type {
7878
($(#[$doc:meta] $oid:tt => $variant:ident: $kind:expr),+) => (
79-
/// A Postgres type
79+
/// A Postgres type.
8080
#[derive(PartialEq, Eq, Clone)]
8181
pub enum Type {
8282
$(
8383
#[$doc]
8484
$variant,
8585
)+
86-
/// An unknown type
86+
/// An unknown type.
8787
Other(Box<Other>),
8888
}
8989

@@ -125,7 +125,7 @@ macro_rules! make_postgres_type {
125125
}
126126
}
127127

128-
/// The kind of this type
128+
/// The kind of this type.
129129
pub fn kind(&self) -> &Kind {
130130
match *self {
131131
$(
@@ -491,13 +491,13 @@ pub trait FromSql: Sized {
491491
impl<T: FromSql> FromSql for Option<T> {
492492
fn from_sql_nullable<R: Read>(ty: &Type, raw: Option<&mut R>) -> Result<Option<T>> {
493493
match raw {
494-
Some(raw) => <T as FromSql>::from_sql(ty, raw).map(|e| Some(e)),
494+
Some(raw) => <T as FromSql>::from_sql(ty, raw).map(Some),
495495
None => Ok(None),
496496
}
497497
}
498498

499499
fn from_sql<R: Read>(ty: &Type, raw: &mut R) -> Result<Option<T>> {
500-
<T as FromSql>::from_sql(ty, raw).map(|e| Some(e))
500+
<T as FromSql>::from_sql(ty, raw).map(Some)
501501
}
502502

503503
fn accepts(ty: &Type) -> bool {
@@ -539,6 +539,14 @@ impl FromSql for String {
539539
}
540540
}
541541

542+
impl FromSql for i8 {
543+
fn from_sql<R: Read>(_: &Type, raw: &mut R) -> Result<i8> {
544+
Ok(try!(raw.read_i8()))
545+
}
546+
547+
accepts!(Type::Char);
548+
}
549+
542550
macro_rules! primitive_from {
543551
($t:ty, $f:ident, $($expected:pat),+) => {
544552
impl FromSql for $t {
@@ -551,14 +559,6 @@ macro_rules! primitive_from {
551559
}
552560
}
553561

554-
impl FromSql for i8 {
555-
fn from_sql<R: Read>(_: &Type, raw: &mut R) -> Result<i8> {
556-
Ok(try!(raw.read_i8()))
557-
}
558-
559-
accepts!(Type::Char);
560-
}
561-
562562
primitive_from!(i16, read_i16, Type::Int2);
563563
primitive_from!(i32, read_i32, Type::Int4);
564564
primitive_from!(u32, read_u32, Type::Oid);
@@ -575,8 +575,7 @@ impl FromSql for HashMap<String, Option<String>> {
575575

576576
for _ in 0..count {
577577
let key_len = try!(raw.read_i32::<BigEndian>());
578-
let mut key = vec![];
579-
key.extend((0..key_len).map(|_| 0));
578+
let mut key = vec![0; key_len as usize];
580579
try!(util::read_all(raw, &mut key));
581580
let key = match String::from_utf8(key) {
582581
Ok(key) => key,
@@ -587,8 +586,7 @@ impl FromSql for HashMap<String, Option<String>> {
587586
let val = if val_len < 0 {
588587
None
589588
} else {
590-
let mut val = vec![];
591-
val.extend((0..val_len).map(|_| 0));
589+
let mut val = vec![0; val_len as usize];
592590
try!(util::read_all(raw, &mut val));
593591
match String::from_utf8(val) {
594592
Ok(val) => Some(val),
@@ -690,7 +688,7 @@ impl ToSql for Vec<u8> {
690688
to_sql_checked!();
691689

692690
fn to_sql<W: Write+?Sized>(&self, ty: &Type, w: &mut W) -> Result<IsNull> {
693-
(&**self).to_sql(ty, w)
691+
<&[u8] as ToSql>::to_sql(&&**self, ty, w)
694692
}
695693

696694
fn accepts(ty: &Type) -> bool {
@@ -725,14 +723,25 @@ impl ToSql for String {
725723
to_sql_checked!();
726724

727725
fn to_sql<W: Write+?Sized>(&self, ty: &Type, w: &mut W) -> Result<IsNull> {
728-
(&**self).to_sql(ty, w)
726+
<&str as ToSql>::to_sql(&&**self, ty, w)
729727
}
730728

731729
fn accepts(ty: &Type) -> bool {
732730
<&str as ToSql>::accepts(ty)
733731
}
734732
}
735733

734+
impl ToSql for i8 {
735+
to_sql_checked!();
736+
737+
fn to_sql<W: Write+?Sized>(&self, _: &Type, mut w: &mut W) -> Result<IsNull> {
738+
try!(w.write_i8(*self));
739+
Ok(IsNull::No)
740+
}
741+
742+
accepts!(Type::Char);
743+
}
744+
736745
macro_rules! to_primitive {
737746
($t:ty, $f:ident, $($expected:pat),+) => {
738747
impl ToSql for $t {
@@ -748,17 +757,6 @@ macro_rules! to_primitive {
748757
}
749758
}
750759

751-
impl ToSql for i8 {
752-
to_sql_checked!();
753-
754-
fn to_sql<W: Write+?Sized>(&self, _: &Type, mut w: &mut W) -> Result<IsNull> {
755-
try!(w.write_i8(*self));
756-
Ok(IsNull::No)
757-
}
758-
759-
accepts!(Type::Char);
760-
}
761-
762760
to_primitive!(i16, write_i16, Type::Int2);
763761
to_primitive!(i32, write_i32, Type::Int4);
764762
to_primitive!(u32, write_u32, Type::Oid);
@@ -772,7 +770,7 @@ impl ToSql for HashMap<String, Option<String>> {
772770
fn to_sql<W: Write+?Sized>(&self, _: &Type, mut w: &mut W) -> Result<IsNull> {
773771
try!(w.write_i32::<BigEndian>(self.len() as i32));
774772

775-
for (key, val) in self.iter() {
773+
for (key, val) in self {
776774
try!(w.write_i32::<BigEndian>(key.len() as i32));
777775
try!(w.write_all(key.as_bytes()));
778776

src/ugh_privacy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl Other {
3434
self.oid
3535
}
3636

37-
/// The kind of this type
37+
/// The kind of this type.
3838
pub fn kind(&self) -> &Kind {
3939
&self.kind
4040
}

0 commit comments

Comments
 (0)