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 <sfackler@gmail.com>"]
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
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
1717
if self.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 as isize - 1));
2123
}
2224
try!(write!(fmt, "="));
@@ -30,7 +32,9 @@ fn fmt_helper<'a, T, I>(depth: usize,
3032
mut data: &mut I,
3133
fmt: &mut fmt::Formatter)
3234
-> fmt::Result
33-
where I: Iterator<Item=&'a T>, T: 'a + fmt::Display {
35+
where I: Iterator<Item = &'a T>,
36+
T: 'a + fmt::Display
37+
{
3438
if depth == dims.len() {
3539
return write!(fmt, "{}", data.next().unwrap());
3640
}
@@ -69,9 +73,9 @@ impl<T> Array<T> {
6973
pub fn from_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
pub fn wrap(&mut self, 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
pub fn iter<'a>(&'a self) -> 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
pub fn iter_mut<'a>(&'a mut self) -> 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
type IntoIter = IntoIter<T>;
256257

257258
fn into_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
fn next(&mut self) -> Option<&'a T> {
274273
self.inner.next()
275274
}
275+
276+
fn size_hint(&self) -> (usize, Option<usize>) {
277+
self.inner.size_hint()
278+
}
276279
}
277280

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

287+
impl<'a, T: 'a> ExactSizeIterator for Iter<'a, T> {
288+
fn len(&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
pub struct IterMut<'a, T: 'a> {
@@ -293,6 +302,10 @@ impl<'a, T: 'a> Iterator for IterMut<'a, T> {
293302
fn next(&mut self) -> Option<&'a mut T> {
294303
self.inner.next()
295304
}
305+
306+
fn size_hint(&self) -> (usize, Option<usize>) {
307+
self.inner.size_hint()
308+
}
296309
}
297310

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

317+
impl<'a, T: 'a> ExactSizeIterator for IterMut<'a, T> {
318+
fn len(&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
pub struct IntoIter<T> {
@@ -313,10 +332,20 @@ impl<T> Iterator for IntoIter<T> {
313332
fn next(&mut self) -> Option<T> {
314333
self.inner.next()
315334
}
335+
336+
fn size_hint(&self) -> (usize, Option<usize>) {
337+
self.inner.size_hint()
338+
}
316339
}
317340

318341
impl<T> DoubleEndedIterator for IntoIter<T> {
319342
fn next_back(&mut self) -> Option<T> {
320343
self.inner.next_back()
321344
}
322345
}
346+
347+
impl<T> ExactSizeIterator for IntoIter<T> {
348+
fn len(&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> FromSql for Array<T> where T: FromSql {
12-
fn from_sql<R: Read>(ty: &Type, raw: &mut R, info: &SessionInfo)
13-
-> postgres::Result<Array<T>> {
11+
impl<T> FromSql for Array<T>
12+
where T: FromSql
13+
{
14+
fn from_sql<R: Read>(ty: &Type, raw: &mut R, 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
let mut limit = raw.take(len as u64);
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
return Err(Error::Conversion(err));
4850
}
4951
}
@@ -55,14 +57,19 @@ impl<T> FromSql for Array<T> where T: FromSql {
5557
fn accepts(ty: &Type) -> bool {
5658
match ty.kind() {
5759
&Kind::Array(ref ty) => <T as FromSql>::accepts(ty),
58-
_ => false
60+
_ => false,
5961
}
6062
}
6163
}
6264

63-
impl<T> ToSql for Array<T> where T: ToSql {
64-
fn to_sql<W: ?Sized+Write>(&self, ty: &Type, mut w: &mut W, info: &SessionInfo)
65-
-> postgres::Result<IsNull> {
65+
impl<T> ToSql for Array<T>
66+
where T: ToSql
67+
{
68+
fn to_sql<W: ?Sized + Write>(&self,
69+
ty: &Type,
70+
mut w: &mut W,
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 in self.dimensions() {
7683
try!(w.write_i32::<BigEndian>(try!(downcast(info.len))));
7784

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

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

113120
fn downcast(len: usize) -> Result<i32> {
114121
if len > i32::max_value() as usize {
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 as i32)
@@ -127,7 +134,8 @@ mod test {
127134
use postgres::types::{FromSql, ToSql};
128135
use Array;
129136

130-
fn test_type<T: PartialEq+FromSql+ToSql, S: fmt::Display>(sql_type: &str, checks: &[(T, S)]) {
137+
fn test_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
fn test_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
fn test_chararray_params() {
172-
test_array_params!("\"char\"", 'a' as i8, "a", 'z' as i8, "z",
173-
'0' as i8, "0");
185+
test_array_params!("\"char\"", 'a' as i8, "a", 'z' as i8, "z", '0' as i8, "0");
174186
}
175187

176188
#[test]
177189
fn test_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
fn test_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
fn test_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
fn test_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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy