Skip to content

Commit ffee117

Browse files
committed
rustfmt
1 parent 9d547b5 commit ffee117

File tree

2 files changed

+191
-97
lines changed

2 files changed

+191
-97
lines changed

src/impls.rs

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
use std::error::Error;
2-
use postgres::types::{Type, Kind, ToSql, FromSql, IsNull};
2+
use postgres::types::{FromSql, IsNull, Kind, ToSql, Type};
33
use postgres_protocol::{self as protocol, types};
44

5-
use {Range, RangeBound, BoundType, BoundSided, Normalizable};
5+
use {BoundSided, BoundType, Normalizable, Range, RangeBound};
66

7-
impl<T> FromSql for Range<T> where T: PartialOrd+Normalizable+FromSql {
7+
impl<T> FromSql for Range<T>
8+
where
9+
T: PartialOrd + Normalizable + FromSql,
10+
{
811
fn from_sql(ty: &Type, raw: &[u8]) -> Result<Range<T>, Box<Error + Sync + Send>> {
912
let element_type = match ty.kind() {
1013
&Kind::Range(ref ty) => ty,
11-
_ => panic!("unexpected type {:?}", ty)
14+
_ => panic!("unexpected type {:?}", ty),
1215
};
1316

1417
match types::range_from_sql(raw)? {
@@ -30,8 +33,9 @@ impl<T> FromSql for Range<T> where T: PartialOrd+Normalizable+FromSql {
3033
}
3134

3235
fn bound_from_sql<T, S>(bound: types::RangeBound<Option<&[u8]>>, ty: &Type) -> Result<Option<RangeBound<S, T>>, Box<Error + Sync + Send>>
33-
where T: PartialOrd + Normalizable + FromSql,
34-
S: BoundSided
36+
where
37+
T: PartialOrd + Normalizable + FromSql,
38+
S: BoundSided,
3539
{
3640
match bound {
3741
types::RangeBound::Exclusive(value) => {
@@ -40,31 +44,36 @@ fn bound_from_sql<T, S>(bound: types::RangeBound<Option<&[u8]>>, ty: &Type) -> R
4044
None => T::from_sql_null(ty)?,
4145
};
4246
Ok(Some(RangeBound::new(value, BoundType::Exclusive)))
43-
},
47+
}
4448
types::RangeBound::Inclusive(value) => {
4549
let value = match value {
4650
Some(value) => T::from_sql(ty, value)?,
4751
None => T::from_sql_null(ty)?,
4852
};
4953
Ok(Some(RangeBound::new(value, BoundType::Inclusive)))
50-
},
54+
}
5155
types::RangeBound::Unbounded => Ok(None),
5256
}
5357
}
5458

55-
impl<T> ToSql for Range<T> where T: PartialOrd+Normalizable+ToSql {
59+
impl<T> ToSql for Range<T>
60+
where
61+
T: PartialOrd + Normalizable + ToSql,
62+
{
5663
fn to_sql(&self, ty: &Type, buf: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>> {
5764
let element_type = match ty.kind() {
5865
&Kind::Range(ref ty) => ty,
59-
_ => panic!("unexpected type {:?}", ty)
66+
_ => panic!("unexpected type {:?}", ty),
6067
};
6168

6269
if self.is_empty() {
6370
types::empty_range_to_sql(buf);
6471
} else {
65-
types::range_to_sql(|buf| bound_to_sql(self.lower(), element_type, buf),
66-
|buf| bound_to_sql(self.upper(), element_type, buf),
67-
buf)?;
72+
types::range_to_sql(
73+
|buf| bound_to_sql(self.lower(), element_type, buf),
74+
|buf| bound_to_sql(self.upper(), element_type, buf),
75+
buf,
76+
)?;
6877
}
6978

7079
Ok(IsNull::No)
@@ -81,8 +90,9 @@ impl<T> ToSql for Range<T> where T: PartialOrd+Normalizable+ToSql {
8190
}
8291

8392
fn bound_to_sql<S, T>(bound: Option<&RangeBound<S, T>>, ty: &Type, buf: &mut Vec<u8>) -> Result<types::RangeBound<protocol::IsNull>, Box<Error + Sync + Send>>
84-
where S: BoundSided,
85-
T: ToSql
93+
where
94+
S: BoundSided,
95+
T: ToSql,
8696
{
8797
match bound {
8898
Some(bound) => {
@@ -98,7 +108,6 @@ fn bound_to_sql<S, T>(bound: Option<&RangeBound<S, T>>, ty: &Type, buf: &mut Vec
98108
}
99109
None => Ok(types::RangeBound::Unbounded),
100110
}
101-
102111
}
103112

104113
#[cfg(test)]
@@ -130,10 +139,11 @@ mod test {
130139
})
131140
}
132141

133-
fn test_type<T: PartialEq+FromSql+ToSql, S: fmt::Display>(sql_type: &str, checks: &[(T, S)]) {
142+
fn test_type<T: PartialEq + FromSql + ToSql, S: fmt::Display>(sql_type: &str, checks: &[(T, S)]) {
134143
let conn = Connection::connect("postgres://postgres@localhost", TlsMode::None).unwrap();
135144
for &(ref val, ref repr) in checks {
136-
let stmt = conn.prepare(&*format!("SELECT {}::{}", *repr, sql_type)).unwrap();
145+
let stmt = conn.prepare(&*format!("SELECT {}::{}", *repr, sql_type))
146+
.unwrap();
137147
let result = stmt.query(&[]).unwrap().iter().next().unwrap().get(0);
138148
assert!(val == &result);
139149

0 commit comments

Comments
 (0)