Skip to content

Commit 42fa212

Browse files
committed
Rustfmt
1 parent 7322308 commit 42fa212

File tree

11 files changed

+228
-74
lines changed

11 files changed

+228
-74
lines changed

src/lib.rs

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,7 @@ impl InnerConnection {
279279
options.push(("database".to_owned(), database));
280280
}
281281

282-
try!(conn.stream.write_message(&frontend::StartupMessage {
283-
parameters: &options,
284-
}));
282+
try!(conn.stream.write_message(&frontend::StartupMessage { parameters: &options }));
285283
try!(conn.stream.flush());
286284

287285
try!(conn.handle_auth(user));
@@ -337,7 +335,8 @@ impl InnerConnection {
337335
}
338336
}
339337

340-
fn read_message_with_notification_nonblocking(&mut self) -> std::io::Result<Option<backend::Message>> {
338+
fn read_message_with_notification_nonblocking(&mut self)
339+
-> std::io::Result<Option<backend::Message>> {
341340
debug_assert!(!self.desynchronized);
342341
loop {
343342
match try_desync!(self, self.stream.read_message_nonblocking()) {
@@ -528,7 +527,8 @@ impl InnerConnection {
528527
let mut values = vec![];
529528
for (param, ty) in params.iter().zip(param_types) {
530529
let mut buf = vec![];
531-
match try!(param.to_sql_checked(ty, &mut buf, &SessionInfo::new(self)).map_err(Error::Conversion)) {
530+
match try!(param.to_sql_checked(ty, &mut buf, &SessionInfo::new(self))
531+
.map_err(Error::Conversion)) {
532532
IsNull::Yes => values.push(None),
533533
IsNull::No => values.push(Some(buf)),
534534
}
@@ -681,18 +681,16 @@ impl InnerConnection {
681681
Some(ref data) => {
682682
try!(Option::<Oid>::from_sql(&Type::Oid, &mut &**data, &ctx)
683683
.map_err(Error::Conversion))
684-
},
684+
}
685685
None => {
686-
try!(Option::<Oid>::from_sql_null(&Type::Oid, &ctx)
687-
.map_err(Error::Conversion))
688-
},
686+
try!(Option::<Oid>::from_sql_null(&Type::Oid, &ctx).map_err(Error::Conversion))
687+
}
689688
};
690689
let basetype = try!(Oid::from_sql(&Type::Oid, &mut &**row[4].as_ref().unwrap(), &ctx)
691690
.map_err(Error::Conversion));
692-
let schema = try!(String::from_sql(&Type::Name,
693-
&mut &**row[5].as_ref().unwrap(),
694-
&ctx)
695-
.map_err(Error::Conversion));
691+
let schema =
692+
try!(String::from_sql(&Type::Name, &mut &**row[5].as_ref().unwrap(), &ctx)
693+
.map_err(Error::Conversion));
696694
let relid = try!(Oid::from_sql(&Type::Oid, &mut &**row[6].as_ref().unwrap(), &ctx)
697695
.map_err(Error::Conversion));
698696
(name, type_, elem_oid, rngsubtype, basetype, schema, relid)
@@ -753,10 +751,8 @@ impl InnerConnection {
753751
let ctx = SessionInfo::new(self);
754752
let mut variants = vec![];
755753
for row in rows {
756-
variants.push(try!(String::from_sql(&Type::Name,
757-
&mut &**row[0].as_ref().unwrap(),
758-
&ctx)
759-
.map_err(Error::Conversion)));
754+
variants.push(try!(String::from_sql(&Type::Name, &mut &**row[0].as_ref().unwrap(), &ctx)
755+
.map_err(Error::Conversion)));
760756
}
761757

762758
Ok(variants)
@@ -789,10 +785,9 @@ impl InnerConnection {
789785
for row in rows {
790786
let (name, type_) = {
791787
let ctx = SessionInfo::new(self);
792-
let name = try!(String::from_sql(&Type::Name,
793-
&mut &**row[0].as_ref().unwrap(),
794-
&ctx)
795-
.map_err(Error::Conversion));
788+
let name =
789+
try!(String::from_sql(&Type::Name, &mut &**row[0].as_ref().unwrap(), &ctx)
790+
.map_err(Error::Conversion));
796791
let type_ = try!(Oid::from_sql(&Type::Oid, &mut &**row[1].as_ref().unwrap(), &ctx)
797792
.map_err(Error::Conversion));
798793
(name, type_)

src/stmt.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,9 @@ impl<'conn> Statement<'conn> {
365365
try!(conn.raw_execute(&self.info.name, "", 0, self.param_types(), params));
366366

367367
let (format, column_formats) = match try!(conn.read_message()) {
368-
backend::Message::CopyOutResponse { format, column_formats } => (format, column_formats),
368+
backend::Message::CopyOutResponse { format, column_formats } => {
369+
(format, column_formats)
370+
}
369371
backend::Message::CopyInResponse { .. } => {
370372
try!(conn.stream.write_message(&frontend::CopyFail { message: "" }));
371373
try!(conn.stream.write_message(&frontend::CopyDone));
@@ -432,14 +434,16 @@ impl<'conn> Statement<'conn> {
432434
}
433435
backend::Message::ErrorResponse { fields } => {
434436
loop {
435-
if let backend::Message::ReadyForQuery { .. } = try!(info.conn.read_message()) {
437+
if let backend::Message::ReadyForQuery { .. } =
438+
try!(info.conn.read_message()) {
436439
return DbError::new(fields);
437440
}
438441
}
439442
}
440443
_ => {
441444
loop {
442-
if let backend::Message::ReadyForQuery { .. } = try!(info.conn.read_message()) {
445+
if let backend::Message::ReadyForQuery { .. } =
446+
try!(info.conn.read_message()) {
443447
return Err(Error::Io(bad_response()));
444448
}
445449
}

src/types/bit_vec.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ impl FromSql for BitVec {
2121
}
2222

2323
impl ToSql for BitVec {
24-
fn to_sql(&self, _: &Type, mut out: &mut Vec<u8>, _: &SessionInfo) -> Result<IsNull, Box<Error + Sync + Send>> {
24+
fn to_sql(&self,
25+
_: &Type,
26+
mut out: &mut Vec<u8>,
27+
_: &SessionInfo)
28+
-> Result<IsNull, Box<Error + Sync + Send>> {
2529
try!(types::varbit_to_sql(self.len(), self.to_bytes().into_iter(), out));
2630
Ok(IsNull::No)
2731
}

src/types/chrono.rs

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ fn base() -> NaiveDateTime {
1212
}
1313

1414
impl FromSql for NaiveDateTime {
15-
fn from_sql(_: &Type, raw: &[u8], _: &SessionInfo) -> Result<NaiveDateTime, Box<Error + Sync + Send>> {
15+
fn from_sql(_: &Type,
16+
raw: &[u8],
17+
_: &SessionInfo)
18+
-> Result<NaiveDateTime, Box<Error + Sync + Send>> {
1619
let t = try!(types::timestamp_from_sql(raw));
1720
Ok(base() + Duration::microseconds(t))
1821
}
@@ -21,7 +24,11 @@ impl FromSql for NaiveDateTime {
2124
}
2225

2326
impl ToSql for NaiveDateTime {
24-
fn to_sql(&self, _: &Type, w: &mut Vec<u8>, _: &SessionInfo) -> Result<IsNull, Box<Error + Sync + Send>> {
27+
fn to_sql(&self,
28+
_: &Type,
29+
w: &mut Vec<u8>,
30+
_: &SessionInfo)
31+
-> Result<IsNull, Box<Error + Sync + Send>> {
2532
let time = match (*self - base()).num_microseconds() {
2633
Some(time) => time,
2734
None => return Err("value too large to transmit".into()),
@@ -35,7 +42,10 @@ impl ToSql for NaiveDateTime {
3542
}
3643

3744
impl FromSql for DateTime<UTC> {
38-
fn from_sql(type_: &Type, raw: &[u8], info: &SessionInfo) -> Result<DateTime<UTC>, Box<Error + Sync + Send>> {
45+
fn from_sql(type_: &Type,
46+
raw: &[u8],
47+
info: &SessionInfo)
48+
-> Result<DateTime<UTC>, Box<Error + Sync + Send>> {
3949
let naive = try!(NaiveDateTime::from_sql(type_, raw, info));
4050
Ok(DateTime::from_utc(naive, UTC))
4151
}
@@ -44,7 +54,11 @@ impl FromSql for DateTime<UTC> {
4454
}
4555

4656
impl ToSql for DateTime<UTC> {
47-
fn to_sql(&self, type_: &Type, w: &mut Vec<u8>, info: &SessionInfo) -> Result<IsNull, Box<Error + Sync + Send>> {
57+
fn to_sql(&self,
58+
type_: &Type,
59+
w: &mut Vec<u8>,
60+
info: &SessionInfo)
61+
-> Result<IsNull, Box<Error + Sync + Send>> {
4862
self.naive_utc().to_sql(type_, w, info)
4963
}
5064

@@ -53,7 +67,10 @@ impl ToSql for DateTime<UTC> {
5367
}
5468

5569
impl FromSql for DateTime<Local> {
56-
fn from_sql(type_: &Type, raw: &[u8], info: &SessionInfo) -> Result<DateTime<Local>, Box<Error + Sync + Send>> {
70+
fn from_sql(type_: &Type,
71+
raw: &[u8],
72+
info: &SessionInfo)
73+
-> Result<DateTime<Local>, Box<Error + Sync + Send>> {
5774
let utc = try!(DateTime::<UTC>::from_sql(type_, raw, info));
5875
Ok(utc.with_timezone(&Local))
5976
}
@@ -62,7 +79,11 @@ impl FromSql for DateTime<Local> {
6279
}
6380

6481
impl ToSql for DateTime<Local> {
65-
fn to_sql(&self, type_: &Type, mut w: &mut Vec<u8>, info: &SessionInfo) -> Result<IsNull, Box<Error + Sync + Send>> {
82+
fn to_sql(&self,
83+
type_: &Type,
84+
mut w: &mut Vec<u8>,
85+
info: &SessionInfo)
86+
-> Result<IsNull, Box<Error + Sync + Send>> {
6687
self.with_timezone(&UTC).to_sql(type_, w, info)
6788
}
6889

@@ -71,7 +92,10 @@ impl ToSql for DateTime<Local> {
7192
}
7293

7394
impl FromSql for DateTime<FixedOffset> {
74-
fn from_sql(type_: &Type, raw: &[u8], info: &SessionInfo) -> Result<DateTime<FixedOffset>, Box<Error + Sync + Send>> {
95+
fn from_sql(type_: &Type,
96+
raw: &[u8],
97+
info: &SessionInfo)
98+
-> Result<DateTime<FixedOffset>, Box<Error + Sync + Send>> {
7599
let utc = try!(DateTime::<UTC>::from_sql(type_, raw, info));
76100
Ok(utc.with_timezone(&FixedOffset::east(0)))
77101
}
@@ -80,7 +104,11 @@ impl FromSql for DateTime<FixedOffset> {
80104
}
81105

82106
impl ToSql for DateTime<FixedOffset> {
83-
fn to_sql(&self, type_: &Type, w: &mut Vec<u8>, info: &SessionInfo) -> Result<IsNull, Box<Error + Sync + Send>> {
107+
fn to_sql(&self,
108+
type_: &Type,
109+
w: &mut Vec<u8>,
110+
info: &SessionInfo)
111+
-> Result<IsNull, Box<Error + Sync + Send>> {
84112
self.with_timezone(&UTC).to_sql(type_, w, info)
85113
}
86114

@@ -89,7 +117,10 @@ impl ToSql for DateTime<FixedOffset> {
89117
}
90118

91119
impl FromSql for NaiveDate {
92-
fn from_sql(_: &Type, raw: &[u8], _: &SessionInfo) -> Result<NaiveDate, Box<Error + Sync + Send>> {
120+
fn from_sql(_: &Type,
121+
raw: &[u8],
122+
_: &SessionInfo)
123+
-> Result<NaiveDate, Box<Error + Sync + Send>> {
93124
let jd = try!(types::date_from_sql(raw));
94125
Ok(base().date() + Duration::days(jd as i64))
95126
}
@@ -98,7 +129,11 @@ impl FromSql for NaiveDate {
98129
}
99130

100131
impl ToSql for NaiveDate {
101-
fn to_sql(&self, _: &Type, w: &mut Vec<u8>, _: &SessionInfo) -> Result<IsNull, Box<Error + Sync + Send>> {
132+
fn to_sql(&self,
133+
_: &Type,
134+
w: &mut Vec<u8>,
135+
_: &SessionInfo)
136+
-> Result<IsNull, Box<Error + Sync + Send>> {
102137
let jd = (*self - base().date()).num_days();
103138
if jd > i32::max_value() as i64 || jd < i32::min_value() as i64 {
104139
return Err("value too large to transmit".into());
@@ -113,7 +148,10 @@ impl ToSql for NaiveDate {
113148
}
114149

115150
impl FromSql for NaiveTime {
116-
fn from_sql(_: &Type, raw: &[u8], _: &SessionInfo) -> Result<NaiveTime, Box<Error + Sync + Send>> {
151+
fn from_sql(_: &Type,
152+
raw: &[u8],
153+
_: &SessionInfo)
154+
-> Result<NaiveTime, Box<Error + Sync + Send>> {
117155
let usec = try!(types::time_from_sql(raw));
118156
Ok(NaiveTime::from_hms(0, 0, 0) + Duration::microseconds(usec))
119157
}
@@ -122,7 +160,11 @@ impl FromSql for NaiveTime {
122160
}
123161

124162
impl ToSql for NaiveTime {
125-
fn to_sql(&self, _: &Type, w: &mut Vec<u8>, _: &SessionInfo) -> Result<IsNull, Box<Error + Sync + Send>> {
163+
fn to_sql(&self,
164+
_: &Type,
165+
w: &mut Vec<u8>,
166+
_: &SessionInfo)
167+
-> Result<IsNull, Box<Error + Sync + Send>> {
126168
let delta = *self - NaiveTime::from_hms(0, 0, 0);
127169
let time = match delta.num_microseconds() {
128170
Some(time) => time,

src/types/eui48.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ use postgres_protocol::types;
77
use types::{FromSql, ToSql, Type, IsNull, SessionInfo};
88

99
impl FromSql for MacAddress {
10-
fn from_sql(_: &Type, raw: &[u8], _: &SessionInfo) -> Result<MacAddress, Box<Error + Sync + Send>> {
10+
fn from_sql(_: &Type,
11+
raw: &[u8],
12+
_: &SessionInfo)
13+
-> Result<MacAddress, Box<Error + Sync + Send>> {
1114
let bytes = try!(types::macaddr_from_sql(raw));
1215
Ok(MacAddress::new(bytes))
1316
}
@@ -16,7 +19,11 @@ impl FromSql for MacAddress {
1619
}
1720

1821
impl ToSql for MacAddress {
19-
fn to_sql(&self, _: &Type, w: &mut Vec<u8>, _: &SessionInfo) -> Result<IsNull, Box<Error + Sync + Send>> {
22+
fn to_sql(&self,
23+
_: &Type,
24+
w: &mut Vec<u8>,
25+
_: &SessionInfo)
26+
-> Result<IsNull, Box<Error + Sync + Send>> {
2027
let mut bytes = [0; 6];
2128
bytes.copy_from_slice(self.as_bytes());
2229
types::macaddr_to_sql(bytes, w);

0 commit comments

Comments
 (0)