Skip to content

Commit 3243417

Browse files
committed
Merge branch 'release-v0.6.2' into release
2 parents 631ad07 + 7b747c7 commit 3243417

File tree

5 files changed

+131
-70
lines changed

5 files changed

+131
-70
lines changed

‎Cargo.toml‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
[package]
22
name = "postgres_array"
3-
version = "0.6.1"
3+
version = "0.6.2"
44
authors = ["Steven Fackler <[email protected]>"]
55
license = "MIT"
66
description = "Array support for rust-postgres"
77
repository = "https://github.com/sfackler/rust-postgres-array"
8-
documentation = "https://sfackler.github.io/rust-postgres-array/doc/v0.6.1/postgres_array"
8+
documentation = "https://sfackler.github.io/rust-postgres-array/doc/v0.6.2/postgres_array"
99

1010
[dependencies]
1111
postgres = "0.11"
12-
byteorder = ">= 0.3, < 0.5"
12+
byteorder = "0.5"
1313

1414
[dev-dependencies]
1515
rustc-serialize = "0.3"
1616
time = "0.1"
1717
uuid = "0.1"
18-
19-
[dev-dependencies.postgres]
20-
features = ["rustc-serialize", "time", "uuid"]
18+
postgres ={version = "0.11", features = ["rustc-serialize", "time", "uuid"] }

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# rust-postgres-array
22
[![Build Status](https://travis-ci.org/sfackler/rust-postgres-array.svg?branch=master)](https://travis-ci.org/sfackler/rust-postgres-array)
33

4-
[Documentation](https://sfackler.github.io/rust-postgres-array/doc/v0.6.1/postgres_array)
4+
[Documentation](https://sfackler.github.io/rust-postgres-array/doc/v0.6.2/postgres_array)
55

66
Support for PostgreSQL arrays in [rust-postgres](https://github.com/sfackler/rust-postgres).

‎src/array.rs‎

Lines changed: 47 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

@@ -273,6 +272,10 @@ impl<'a, T: 'a> Iterator for Iter<'a, T>{
273272
fnnext(&mutself) -> Option<&'aT>{
274273
self.inner.next()
275274
}
275+
276+
fnsize_hint(&self) -> (usize,Option<usize>){
277+
self.inner.size_hint()
278+
}
276279
}
277280

278281
impl<'a,T:'a>DoubleEndedIteratorforIter<'a,T>{
@@ -281,6 +284,12 @@ impl<'a, T: 'a> DoubleEndedIterator for Iter<'a, T>{
281284
}
282285
}
283286

287+
impl<'a,T:'a>ExactSizeIteratorforIter<'a,T>{
288+
fnlen(&self) -> usize{
289+
self.inner.len()
290+
}
291+
}
292+
284293
/// An iterator over mutable references to values of an `Array` in the
285294
/// higher-dimensional equivalent of row-major order.
286295
pubstructIterMut<'a,T:'a>{
@@ -293,6 +302,10 @@ impl<'a, T: 'a> Iterator for IterMut<'a, T>{
293302
fnnext(&mutself) -> Option<&'amutT>{
294303
self.inner.next()
295304
}
305+
306+
fnsize_hint(&self) -> (usize,Option<usize>){
307+
self.inner.size_hint()
308+
}
296309
}
297310

298311
impl<'a,T:'a>DoubleEndedIteratorforIterMut<'a,T>{
@@ -301,6 +314,12 @@ impl<'a, T: 'a> DoubleEndedIterator for IterMut<'a, T>{
301314
}
302315
}
303316

317+
impl<'a,T:'a>ExactSizeIteratorforIterMut<'a,T>{
318+
fnlen(&self) -> usize{
319+
self.inner.len()
320+
}
321+
}
322+
304323
/// An iterator over values of an `Array` in the higher-dimensional
305324
/// equivalent of row-major order.
306325
pubstructIntoIter<T>{
@@ -313,10 +332,20 @@ impl<T> Iterator for IntoIter<T>{
313332
fnnext(&mutself) -> Option<T>{
314333
self.inner.next()
315334
}
335+
336+
fnsize_hint(&self) -> (usize,Option<usize>){
337+
self.inner.size_hint()
338+
}
316339
}
317340

318341
impl<T>DoubleEndedIteratorforIntoIter<T>{
319342
fnnext_back(&mutself) -> Option<T>{
320343
self.inner.next_back()
321344
}
322345
}
346+
347+
impl<T>ExactSizeIteratorforIntoIter<T>{
348+
fnlen(&self) -> usize{
349+
self.inner.len()
350+
}
351+
}

‎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]

0 commit comments

Comments
(0)