Skip to content

Commit a405aa8

Browse files
committed
rustfmt
1 parent 1a309b9 commit a405aa8

File tree

3 files changed

+95
-62
lines changed

3 files changed

+95
-62
lines changed

‎src/array.rs‎

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ impl<T: fmt::Display> fmt::Display for Array<T>{
1616
fnfmt(&self,fmt:&mut fmt::Formatter) -> fmt::Result{
1717
ifself.dims.iter().any(|dim| dim.lower_bound != 1){
1818
for dim in&self.dims{
19-
try!(write!(fmt,"[{}:{}]", dim.lower_bound,
19+
try!(write!(fmt,
20+
"[{}:{}]",
21+
dim.lower_bound,
2022
dim.lower_bound + dim.len asisize - 1));
2123
}
2224
try!(write!(fmt,"="));
@@ -30,7 +32,9 @@ fn fmt_helper<'a, T, I>(depth: usize,
3032
mutdata:&mutI,
3133
fmt:&mut fmt::Formatter)
3234
-> fmt::Result
33-
whereI:Iterator<Item=&'aT>,T:'a + fmt::Display{
35+
whereI:Iterator<Item = &'aT>,
36+
T:'a + fmt::Display
37+
{
3438
if depth == dims.len(){
3539
returnwrite!(fmt,"{}", data.next().unwrap());
3640
}
@@ -69,9 +73,9 @@ impl<T> Array<T>{
6973
pubfnfrom_vec(data:Vec<T>,lower_bound:isize) -> Array<T>{
7074
Array{
7175
dims:vec![Dimension{
72-
len: data.len(),
73-
lower_bound: lower_bound
74-
}],
76+
len: data.len(),
77+
lower_bound: lower_bound,
78+
}],
7579
data: data,
7680
}
7781
}
@@ -81,10 +85,11 @@ impl<T> Array<T>{
8185
/// For example, the one dimensional array `[1, 2]` would turn into the
8286
/// two-dimensional array `[[1, 2]]`.
8387
pubfnwrap(&mutself,lower_bound:isize){
84-
self.dims.insert(0,Dimension{
85-
len:1,
86-
lower_bound: lower_bound,
87-
});
88+
self.dims.insert(0,
89+
Dimension{
90+
len:1,
91+
lower_bound: lower_bound,
92+
});
8893
}
8994

9095
/// Consumes another array, appending it to the top level dimension of this
@@ -131,17 +136,13 @@ impl<T> Array<T>{
131136
/// Returns an iterator over references to the elements of the array in the
132137
/// higher-dimensional equivalent of row-major order.
133138
pubfniter<'a>(&'aself) -> Iter<'a,T>{
134-
Iter{
135-
inner:self.data.iter(),
136-
}
139+
Iter{inner:self.data.iter()}
137140
}
138141

139142
/// Returns an iterator over mutable references to the elements of the
140143
/// array in the higher-dimensional equivalent of row-major order.
141144
pubfniter_mut<'a>(&'amutself) -> IterMut<'a,T>{
142-
IterMut{
143-
inner:self.data.iter_mut(),
144-
}
145+
IterMut{inner:self.data.iter_mut()}
145146
}
146147
}
147148

@@ -255,9 +256,7 @@ impl<T> IntoIterator for Array<T>{
255256
typeIntoIter = IntoIter<T>;
256257

257258
fninto_iter(self) -> IntoIter<T>{
258-
IntoIter{
259-
inner:self.data.into_iter()
260-
}
259+
IntoIter{inner:self.data.into_iter()}
261260
}
262261
}
263262

‎src/impls.rs‎

Lines changed: 59 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ use postgres::types::{Type, Kind, ToSql, FromSql, Oid, IsNull, SessionInfo};
88

99
use{Array,Dimension};
1010

11-
impl<T>FromSqlforArray<T>whereT:FromSql{
12-
fnfrom_sql<R:Read>(ty:&Type,raw:&mutR,info:&SessionInfo)
13-
-> postgres::Result<Array<T>>{
11+
impl<T>FromSqlforArray<T>
12+
whereT:FromSql
13+
{
14+
fnfrom_sql<R:Read>(ty:&Type,raw:&mutR,info:&SessionInfo) -> postgres::Result<Array<T>>{
1415
let element_type = match ty.kind(){
1516
&Kind::Array(ref ty) => ty,
1617
_ => panic!("unexpected type{:?}", ty),
@@ -42,8 +43,9 @@ impl<T> FromSql for Array<T> where T: FromSql{
4243
letmut limit = raw.take(len asu64);
4344
elements.push(try!(FromSql::from_sql(&element_type,&mut limit, info)));
4445
if limit.limit() != 0{
45-
let err:Box<error::Error+Sync+Send> =
46-
"from_sql call did not consume all data".into();
46+
let err:Box<error::Error + Sync + Send> = "from_sql call did not consume all \
47+
data"
48+
.into();
4749
returnErr(Error::Conversion(err));
4850
}
4951
}
@@ -55,14 +57,19 @@ impl<T> FromSql for Array<T> where T: FromSql{
5557
fnaccepts(ty:&Type) -> bool{
5658
match ty.kind(){
5759
&Kind::Array(ref ty) => <TasFromSql>::accepts(ty),
58-
_ => false
60+
_ => false,
5961
}
6062
}
6163
}
6264

63-
impl<T>ToSqlforArray<T>whereT:ToSql{
64-
fnto_sql<W: ?Sized+Write>(&self,ty:&Type,mutw:&mutW,info:&SessionInfo)
65-
-> postgres::Result<IsNull>{
65+
impl<T>ToSqlforArray<T>
66+
whereT:ToSql
67+
{
68+
fnto_sql<W: ?Sized + Write>(&self,
69+
ty:&Type,
70+
mutw:&mutW,
71+
info:&SessionInfo)
72+
-> postgres::Result<IsNull>{
6673
let element_type = match ty.kind(){
6774
&Kind::Array(ref ty) => ty,
6875
_ => panic!("unexpected type{:?}", ty),
@@ -75,9 +82,9 @@ impl<T> ToSql for Array<T> where T: ToSql{
7582
for info inself.dimensions(){
7683
try!(w.write_i32::<BigEndian>(try!(downcast(info.len))));
7784

78-
let bound = if info.lower_bound > i32::max_value()asisize
79-
|| info.lower_bound < i32::min_value()asisize{
80-
let err:Box<error::Error+Sync+Send> = "value too large to transmit".into();
85+
let bound = if info.lower_bound > i32::max_value()asisize ||
86+
info.lower_bound < i32::min_value()asisize{
87+
let err:Box<error::Error + Sync + Send> = "value too large to transmit".into();
8188
returnErr(Error::Conversion(err));
8289
}else{
8390
info.lower_boundasi32
@@ -103,7 +110,7 @@ impl<T> ToSql for Array<T> where T: ToSql{
103110
fnaccepts(ty:&Type) -> bool{
104111
match ty.kind(){
105112
&Kind::Array(ref ty) => <TasToSql>::accepts(ty),
106-
_ => false
113+
_ => false,
107114
}
108115
}
109116

@@ -112,7 +119,7 @@ impl<T> ToSql for Array<T> where T: ToSql{
112119

113120
fndowncast(len:usize) -> Result<i32>{
114121
if len > i32::max_value()asusize{
115-
let err:Box<error::Error+Sync+Send> = "value too large to transmit".into();
122+
let err:Box<error::Error + Sync + Send> = "value too large to transmit".into();
116123
Err(Error::Conversion(err))
117124
}else{
118125
Ok(len asi32)
@@ -127,7 +134,8 @@ mod test{
127134
use postgres::types::{FromSql,ToSql};
128135
useArray;
129136

130-
fntest_type<T:PartialEq+FromSql+ToSql,S: fmt::Display>(sql_type:&str,checks:&[(T,S)]){
137+
fntest_type<T:PartialEq + FromSql + ToSql,S: fmt::Display>(sql_type:&str,
138+
checks:&[(T,S)]){
131139
let conn = Connection::connect("postgres://postgres@localhost",SslMode::None).unwrap();
132140
for&(ref val,ref repr)in checks.iter(){
133141
let stmt = conn.prepare(&format!("SELECT{}::{}",*repr, sql_type)).unwrap();
@@ -163,20 +171,29 @@ mod test{
163171

164172
#[test]
165173
fntest_byteaarray_params(){
166-
test_array_params!("BYTEA", vec!(0u8,1),r#""\\x0001""#, vec!(254u8,255u8),
167-
r#""\\xfeff""#, vec!(10u8,11u8),r#""\\x0a0b""#);
174+
test_array_params!("BYTEA",
175+
vec![0u8,1],
176+
r#""\\x0001""#,
177+
vec![254u8,255u8],
178+
r#""\\xfeff""#,
179+
vec![10u8,11u8],
180+
r#""\\x0a0b""#);
168181
}
169182

170183
#[test]
171184
fntest_chararray_params(){
172-
test_array_params!("\"char\"",'a'asi8,"a",'z'asi8,"z",
173-
'0'asi8,"0");
185+
test_array_params!("\"char\"",'a'asi8,"a",'z'asi8,"z",'0'asi8,"0");
174186
}
175187

176188
#[test]
177189
fntest_namearray_params(){
178-
test_array_params!("NAME","hello".to_string(),"hello","world".to_string(),
179-
"world","!".to_string(),"!");
190+
test_array_params!("NAME",
191+
"hello".to_string(),
192+
"hello",
193+
"world".to_string(),
194+
"world",
195+
"!".to_string(),
196+
"!");
180197
}
181198

182199
#[test]
@@ -191,20 +208,35 @@ mod test{
191208

192209
#[test]
193210
fntest_textarray_params(){
194-
test_array_params!("TEXT","hello".to_string(),"hello","world".to_string(),
195-
"world","!".to_string(),"!");
211+
test_array_params!("TEXT",
212+
"hello".to_string(),
213+
"hello",
214+
"world".to_string(),
215+
"world",
216+
"!".to_string(),
217+
"!");
196218
}
197219

198220
#[test]
199221
fntest_charnarray_params(){
200-
test_array_params!("CHAR(5)","hello".to_string(),"hello",
201-
"world".to_string(),"world","! ".to_string(),"!");
222+
test_array_params!("CHAR(5)",
223+
"hello".to_string(),
224+
"hello",
225+
"world".to_string(),
226+
"world",
227+
"! ".to_string(),
228+
"!");
202229
}
203230

204231
#[test]
205232
fntest_varchararray_params(){
206-
test_array_params!("VARCHAR","hello".to_string(),"hello",
207-
"world".to_string(),"world","!".to_string(),"!");
233+
test_array_params!("VARCHAR",
234+
"hello".to_string(),
235+
"hello",
236+
"world".to_string(),
237+
"world",
238+
"!".to_string(),
239+
"!");
208240
}
209241

210242
#[test]

‎src/lib.rs‎

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,19 @@ mod tests{
3838

3939
#[test]
4040
fntest_from_vec(){
41-
let a = Array::from_vec(vec!(0i32,1,2), -1);
42-
assert!(&[Dimension{ len:3, lower_bound: -1}][..] ==
43-
a.dimensions());
41+
let a = Array::from_vec(vec![0i32,1,2], -1);
42+
assert!(&[Dimension{
43+
len:3,
44+
lower_bound: -1,
45+
}][..] == a.dimensions());
4446
assert_eq!(0, a[-1]);
4547
assert_eq!(1, a[0]);
4648
assert_eq!(2, a[1]);
4749
}
4850

4951
#[test]
5052
fntest_2d_slice_get(){
51-
letmut a = Array::from_vec(vec!(0i32,1,2), -1);
53+
letmut a = Array::from_vec(vec![0i32,1,2], -1);
5254
a.wrap(1);
5355
assert_eq!(0, a[(1, -1)]);
5456
assert_eq!(1, a[(1,0)]);
@@ -58,33 +60,33 @@ mod tests{
5860
#[test]
5961
#[should_panic]
6062
fntest_push_wrong_lower_bound(){
61-
letmut a = Array::from_vec(vec!(1i32), -1);
62-
a.push(Array::from_vec(vec!(2),0));
63+
letmut a = Array::from_vec(vec![1i32], -1);
64+
a.push(Array::from_vec(vec![2],0));
6365
}
6466

6567
#[test]
6668
#[should_panic]
6769
fntest_push_wrong_dims(){
68-
letmut a = Array::from_vec(vec!(1i32), -1);
70+
letmut a = Array::from_vec(vec![1i32], -1);
6971
a.wrap(1);
70-
a.push(Array::from_vec(vec!(1,2), -1));
72+
a.push(Array::from_vec(vec![1,2], -1));
7173
}
7274

7375
#[test]
7476
#[should_panic]
7577
fntest_push_wrong_dim_count(){
76-
letmut a = Array::from_vec(vec!(1i32), -1);
78+
letmut a = Array::from_vec(vec![1i32], -1);
7779
a.wrap(1);
78-
letmut b = Array::from_vec(vec!(2), -1);
80+
letmut b = Array::from_vec(vec![2], -1);
7981
b.wrap(1);
8082
a.push(b);
8183
}
8284

8385
#[test]
8486
fntest_push_ok(){
85-
letmut a = Array::from_vec(vec!(1i32,2),0);
87+
letmut a = Array::from_vec(vec![1i32,2],0);
8688
a.wrap(0);
87-
a.push(Array::from_vec(vec!(3,4),0));
89+
a.push(Array::from_vec(vec![3,4],0));
8890
assert_eq!(1, a[(0,0)]);
8991
assert_eq!(2, a[(0,1)]);
9092
assert_eq!(3, a[(1,0)]);
@@ -93,13 +95,13 @@ mod tests{
9395

9496
#[test]
9597
fntest_3d(){
96-
letmut a = Array::from_vec(vec!(0i32,1),0);
98+
letmut a = Array::from_vec(vec![0i32,1],0);
9799
a.wrap(0);
98-
a.push(Array::from_vec(vec!(2,3),0));
100+
a.push(Array::from_vec(vec![2,3],0));
99101
a.wrap(0);
100-
letmut b = Array::from_vec(vec!(4,5),0);
102+
letmut b = Array::from_vec(vec![4,5],0);
101103
b.wrap(0);
102-
b.push(Array::from_vec(vec!(6,7),0));
104+
b.push(Array::from_vec(vec![6,7],0));
103105
a.push(b);
104106
assert_eq!(0, a[(0,0,0)]);
105107
assert_eq!(1, a[(0,0,1)]);
@@ -113,7 +115,7 @@ mod tests{
113115

114116
#[test]
115117
fntest_mut(){
116-
letmut a = Array::from_vec(vec!(1i32,2),0);
118+
letmut a = Array::from_vec(vec![1i32,2],0);
117119
a.wrap(0);
118120
a[(0,0)] = 3;
119121
assert_eq!(3, a[(0,0)]);

0 commit comments

Comments
(0)