From 0f0c7c767abfc45d012d434924728613706113cc Mon Sep 17 00:00:00 2001
From: plafue
Date: Wed, 19 Jul 2017 14:43:16 +0200
Subject: [PATCH 01/14] Updates postgres dependency to 0.14
---
Cargo.toml | 8 ++++----
src/impls.rs | 10 +++++-----
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/Cargo.toml b/Cargo.toml
index 91e44c3..b0f912b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,13 +1,13 @@
[package]
name = "postgres_array"
-version = "0.7.1"
+version = "0.8.0"
authors = ["Steven Fackler "]
license = "MIT"
description = "Array support for rust-postgres"
repository = "https://github.com/sfackler/rust-postgres-array"
-documentation = "https://sfackler.github.io/rust-postgres-array/doc/v0.7.1/postgres_array"
+documentation = "https://sfackler.github.io/rust-postgres-array/doc/v0.8.0/postgres_array"
[dependencies]
fallible-iterator = "0.1"
-postgres = ">= 0.12, < 0.14"
-postgres-protocol = "0.1"
+postgres = "0.14"
+postgres-protocol = "0.3"
diff --git a/src/impls.rs b/src/impls.rs
index 6eda63a..ad05c2e 100644
--- a/src/impls.rs
+++ b/src/impls.rs
@@ -1,5 +1,5 @@
use fallible_iterator::FallibleIterator;
-use postgres::types::{Type, Kind, ToSql, FromSql, IsNull, SessionInfo};
+use postgres::types::{Type, Kind, ToSql, FromSql, IsNull};
use postgres_protocol::types;
use postgres_protocol;
use std::error::Error;
@@ -9,7 +9,7 @@ use {Array, Dimension};
impl FromSql for Array
where T: FromSql
{
- fn from_sql(ty: &Type, raw: &[u8], info: &SessionInfo) -> Result, Box> {
+ fn from_sql(ty: &Type, raw: &[u8]) -> Result, Box> {
let element_type = match *ty.kind() {
Kind::Array(ref ty) => ty,
_ => unreachable!(),
@@ -24,7 +24,7 @@ impl FromSql for Array
.collect());
let elements = try!(array.values()
- .and_then(|v| FromSql::from_sql_nullable(element_type, v, info))
+ .and_then(|v| FromSql::from_sql_nullable(element_type, v))
.collect());
Ok(Array::from_parts(elements, dimensions))
@@ -41,7 +41,7 @@ impl FromSql for Array
impl ToSql for Array
where T: ToSql
{
- fn to_sql(&self, ty: &Type, w: &mut Vec, info: &SessionInfo) -> Result> {
+ fn to_sql(&self, ty: &Type, w: &mut Vec) -> Result> {
let element_type = match ty.kind() {
&Kind::Array(ref ty) => ty,
_ => unreachable!(),
@@ -62,7 +62,7 @@ impl ToSql for Array
element_type.oid(),
elements,
|v, w| {
- match v.to_sql(element_type, w, info) {
+ match v.to_sql(element_type, w) {
Ok(IsNull::Yes) => Ok(postgres_protocol::IsNull::Yes),
Ok(IsNull::No) => Ok(postgres_protocol::IsNull::No),
Err(e) => Err(e),
From f9d93c0be321566ef60c09d1be44cb08b003920b Mon Sep 17 00:00:00 2001
From: Steven Fackler
Date: Wed, 19 Jul 2017 08:24:06 -0700
Subject: [PATCH 02/14] Release v0.8.0
---
Cargo.toml | 2 +-
src/lib.rs | 21 ++++++++++++++-------
2 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/Cargo.toml b/Cargo.toml
index b0f912b..d7df5f5 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -5,7 +5,7 @@ authors = ["Steven Fackler "]
license = "MIT"
description = "Array support for rust-postgres"
repository = "https://github.com/sfackler/rust-postgres-array"
-documentation = "https://sfackler.github.io/rust-postgres-array/doc/v0.8.0/postgres_array"
+documentation = "https://docs.rs/postgres_array/0.8.0/postgres_array"
[dependencies]
fallible-iterator = "0.1"
diff --git a/src/lib.rs b/src/lib.rs
index e29dbdb..91f0b00 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,5 +1,5 @@
//! Multi-dimensional arrays with per-dimension specifiable lower bounds
-#![doc(html_root_url="https://sfackler.github.io/rust-postgres-array/doc/v0.7.1")]
+#![doc(html_root_url="https://docs.rs/postgres_array/0.8.0")]
extern crate fallible_iterator;
#[macro_use]
@@ -25,8 +25,10 @@ impl Dimension {
fn shift(&self, idx: i32) -> i32 {
let offset = self.lower_bound;
assert!(idx >= offset, "out of bounds array access");
- assert!(offset >= 0 || idx <= 0 || i32::max_value() - (-offset) >= idx,
- "out of bounds array access");
+ assert!(
+ offset >= 0 || idx <= 0 || i32::max_value() - (-offset) >= idx,
+ "out of bounds array access"
+ );
match idx.checked_sub(offset) {
Some(shifted) => shifted,
None => panic!("out of bounds array access"),
@@ -41,10 +43,15 @@ mod tests {
#[test]
fn test_from_vec() {
let a = Array::from_vec(vec![0i32, 1, 2], -1);
- assert!(&[Dimension {
- len: 3,
- lower_bound: -1,
- }][..] == a.dimensions());
+ assert!(
+ &[
+ Dimension {
+ len: 3,
+ lower_bound: -1,
+ },
+ ]
+ [..] == a.dimensions()
+ );
assert_eq!(0, a[-1]);
assert_eq!(1, a[0]);
assert_eq!(2, a[1]);
From 54f72f53ae1607d29db00b936f220c10d0afa735 Mon Sep 17 00:00:00 2001
From: Steven Fackler
Date: Sun, 23 Jul 2017 13:34:26 -0700
Subject: [PATCH 03/14] Switch tests to circle
---
.travis.yml | 9 ---
circle.yml | 26 ++++++++
src/array.rs | 83 +++++++++++++++++--------
src/impls.rs | 170 ++++++++++++++++++++++++++++++---------------------
4 files changed, 182 insertions(+), 106 deletions(-)
delete mode 100644 .travis.yml
create mode 100644 circle.yml
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 3de70e9..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,9 +0,0 @@
-language: rust
-rust:
-- nightly
-- beta
-- stable
-addons:
- postgresql: 9.4
-script:
-- cargo test
diff --git a/circle.yml b/circle.yml
new file mode 100644
index 0000000..a648ab0
--- /dev/null
+++ b/circle.yml
@@ -0,0 +1,26 @@
+version: 2
+jobs:
+ build:
+ working_directory: ~/build
+ docker:
+ - image: jimmycuadra/rust:1.19.0
+ - image: postgres:9.6
+ environment:
+ POSTGRES_PASSWORD: password
+ steps:
+ - checkout
+ - restore_cache:
+ key: registry
+ - run: cargo generate-lockfile
+ - save_cache:
+ key: registry-{{ epoch }}
+ paths:
+ - ~/.cargo/registry/index
+ - restore_cache:
+ key: dependencies-1.19-{{ checksum "Cargo.lock" }}
+ - run: cargo test
+ - save_cache:
+ key: dependencies-1.19-{{ checksum "Cargo.lock" }}
+ paths:
+ - target
+ - ~/.cargo/registry/cache
diff --git a/src/array.rs b/src/array.rs
index 4a091ff..1cf85b3 100644
--- a/src/array.rs
+++ b/src/array.rs
@@ -16,10 +16,12 @@ impl fmt::Display for Array {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
if self.dims.iter().any(|dim| dim.lower_bound != 1) {
for dim in &self.dims {
- try!(write!(fmt,
- "[{}:{}]",
- dim.lower_bound,
- dim.lower_bound + dim.len - 1));
+ try!(write!(
+ fmt,
+ "[{}:{}]",
+ dim.lower_bound,
+ dim.lower_bound + dim.len - 1
+ ));
}
try!(write!(fmt, "="));
}
@@ -27,13 +29,15 @@ impl fmt::Display for Array {
}
}
-fn fmt_helper<'a, T, I>(depth: usize,
- dims: &[Dimension],
- mut data: &mut I,
- fmt: &mut fmt::Formatter)
- -> fmt::Result
- where I: Iterator- ,
- T: 'a + fmt::Display
+fn fmt_helper<'a, T, I>(
+ depth: usize,
+ dims: &[Dimension],
+ mut data: &mut I,
+ fmt: &mut fmt::Formatter,
+) -> fmt::Result
+where
+ I: Iterator
- ,
+ T: 'a + fmt::Display,
{
if depth == dims.len() {
return write!(fmt, "{}", data.next().unwrap());
@@ -60,9 +64,11 @@ impl Array {
/// Panics if the number of elements provided does not match the number of
/// elements specified by the dimensions.
pub fn from_parts(data: Vec, dimensions: Vec) -> Array {
- assert!((data.is_empty() && dimensions.is_empty()) ||
+ assert!(
+ (data.is_empty() && dimensions.is_empty()) ||
data.len() as i32 == dimensions.iter().fold(1, |acc, i| acc * i.len),
- "size mismatch");
+ "size mismatch"
+ );
Array {
dims: dimensions,
data: data,
@@ -72,10 +78,12 @@ impl Array {
/// Creates a new one-dimensional array.
pub fn from_vec(data: Vec, lower_bound: i32) -> Array {
Array {
- dims: vec![Dimension {
- len: data.len() as i32,
- lower_bound: lower_bound,
- }],
+ dims: vec![
+ Dimension {
+ len: data.len() as i32,
+ lower_bound: lower_bound,
+ },
+ ],
data: data,
}
}
@@ -85,11 +93,13 @@ impl Array {
/// For example, the one dimensional array `[1, 2]` would turn into the
/// two-dimensional array `[[1, 2]]`.
pub fn wrap(&mut self, lower_bound: i32) {
- self.dims.insert(0,
- Dimension {
- len: 1,
- lower_bound: lower_bound,
- });
+ self.dims.insert(
+ 0,
+ Dimension {
+ len: 1,
+ lower_bound: lower_bound,
+ },
+ );
}
/// Consumes another array, appending it to the top level dimension of this
@@ -106,8 +116,10 @@ impl Array {
///
/// Panics if the dimensions of the two arrays do not match.
pub fn push(&mut self, other: Array) {
- assert!(self.dims.len() - 1 == other.dims.len(),
- "cannot append differently shaped arrays");
+ assert!(
+ self.dims.len() - 1 == other.dims.len(),
+ "cannot append differently shaped arrays"
+ );
for (dim1, dim2) in self.dims.iter().skip(1).zip(other.dims.iter()) {
assert!(dim1 == dim2, "cannot append differently shaped arrays");
}
@@ -196,8 +208,27 @@ tuple_impl!(a: i32, b: i32, c: i32, d: i32);
tuple_impl!(a: i32, b: i32, c: i32, d: i32, e: i32);
tuple_impl!(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32);
tuple_impl!(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32, g: i32);
-tuple_impl!(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32, g: i32, h: i32);
-tuple_impl!(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32, g: i32, h: i32, i: i32);
+tuple_impl!(
+ a: i32,
+ b: i32,
+ c: i32,
+ d: i32,
+ e: i32,
+ f: i32,
+ g: i32,
+ h: i32
+);
+tuple_impl!(
+ a: i32,
+ b: i32,
+ c: i32,
+ d: i32,
+ e: i32,
+ f: i32,
+ g: i32,
+ h: i32,
+ i: i32
+);
/// Indexes into the `Array`, retrieving a reference to the contained
/// value.
diff --git a/src/impls.rs b/src/impls.rs
index ad05c2e..841be0d 100644
--- a/src/impls.rs
+++ b/src/impls.rs
@@ -7,7 +7,8 @@ use std::error::Error;
use {Array, Dimension};
impl FromSql for Array
- where T: FromSql
+where
+ T: FromSql,
{
fn from_sql(ty: &Type, raw: &[u8]) -> Result, Box> {
let element_type = match *ty.kind() {
@@ -17,15 +18,24 @@ impl FromSql for Array
let array = try!(types::array_from_sql(raw));
- let dimensions = try!(array.dimensions()
- .map(|d| {
- Dimension { len: d.len, lower_bound: d.lower_bound }
- })
- .collect());
-
- let elements = try!(array.values()
- .and_then(|v| FromSql::from_sql_nullable(element_type, v))
- .collect());
+ let dimensions = try!(
+ array
+ .dimensions()
+ .map(|d| {
+ Dimension {
+ len: d.len,
+ lower_bound: d.lower_bound,
+ }
+ })
+ .collect()
+ );
+
+ let elements = try!(
+ array
+ .values()
+ .and_then(|v| FromSql::from_sql_nullable(element_type, v))
+ .collect()
+ );
Ok(Array::from_parts(elements, dimensions))
}
@@ -39,7 +49,8 @@ impl FromSql for Array
}
impl ToSql for Array
- where T: ToSql
+where
+ T: ToSql,
{
fn to_sql(&self, ty: &Type, w: &mut Vec) -> Result> {
let element_type = match ty.kind() {
@@ -47,28 +58,26 @@ impl ToSql for Array
_ => unreachable!(),
};
- let dimensions = self.dimensions()
- .iter()
- .map(|d| {
- types::ArrayDimension {
- len: d.len,
- lower_bound: d.lower_bound,
- }
- });
+ let dimensions = self.dimensions().iter().map(|d| {
+ types::ArrayDimension {
+ len: d.len,
+ lower_bound: d.lower_bound,
+ }
+ });
let elements = self.iter();
- try!(types::array_to_sql(dimensions,
- true,
- element_type.oid(),
- elements,
- |v, w| {
- match v.to_sql(element_type, w) {
- Ok(IsNull::Yes) => Ok(postgres_protocol::IsNull::Yes),
- Ok(IsNull::No) => Ok(postgres_protocol::IsNull::No),
- Err(e) => Err(e),
- }
- },
- w));
+ try!(types::array_to_sql(
+ dimensions,
+ true,
+ element_type.oid(),
+ elements,
+ |v, w| match v.to_sql(element_type, w) {
+ Ok(IsNull::Yes) => Ok(postgres_protocol::IsNull::Yes),
+ Ok(IsNull::No) => Ok(postgres_protocol::IsNull::No),
+ Err(e) => Err(e),
+ },
+ w,
+ ));
Ok(IsNull::No)
}
@@ -91,11 +100,15 @@ mod test {
use postgres::types::{FromSql, ToSql};
use Array;
- fn test_type(sql_type: &str,
- checks: &[(T, S)]) {
- let conn = Connection::connect("postgres://postgres@localhost", TlsMode::None).unwrap();
+ fn test_type(
+ sql_type: &str,
+ checks: &[(T, S)],
+ ) {
+ let conn = Connection::connect("postgres://postgres:password@localhost", TlsMode::None)
+ .unwrap();
for &(ref val, ref repr) in checks.iter() {
- let stmt = conn.prepare(&format!("SELECT {}::{}", *repr, sql_type)).unwrap();
+ let stmt = conn.prepare(&format!("SELECT {}::{}", *repr, sql_type))
+ .unwrap();
let result = stmt.query(&[]).unwrap().iter().next().unwrap().get(0);
assert!(val == &result);
@@ -128,13 +141,15 @@ mod test {
#[test]
fn test_byteaarray_params() {
- test_array_params!("BYTEA",
- vec![0u8, 1],
- r#""\\x0001""#,
- vec![254u8, 255u8],
- r#""\\xfeff""#,
- vec![10u8, 11u8],
- r#""\\x0a0b""#);
+ test_array_params!(
+ "BYTEA",
+ vec![0u8, 1],
+ r#""\\x0001""#,
+ vec![254u8, 255u8],
+ r#""\\xfeff""#,
+ vec![10u8, 11u8],
+ r#""\\x0a0b""#
+ );
}
#[test]
@@ -144,13 +159,15 @@ mod test {
#[test]
fn test_namearray_params() {
- test_array_params!("NAME",
- "hello".to_string(),
- "hello",
- "world".to_string(),
- "world",
- "!".to_string(),
- "!");
+ test_array_params!(
+ "NAME",
+ "hello".to_string(),
+ "hello",
+ "world".to_string(),
+ "world",
+ "!".to_string(),
+ "!"
+ );
}
#[test]
@@ -165,35 +182,41 @@ mod test {
#[test]
fn test_textarray_params() {
- test_array_params!("TEXT",
- "hello".to_string(),
- "hello",
- "world".to_string(),
- "world",
- "!".to_string(),
- "!");
+ test_array_params!(
+ "TEXT",
+ "hello".to_string(),
+ "hello",
+ "world".to_string(),
+ "world",
+ "!".to_string(),
+ "!"
+ );
}
#[test]
fn test_charnarray_params() {
- test_array_params!("CHAR(5)",
- "hello".to_string(),
- "hello",
- "world".to_string(),
- "world",
- "! ".to_string(),
- "!");
+ test_array_params!(
+ "CHAR(5)",
+ "hello".to_string(),
+ "hello",
+ "world".to_string(),
+ "world",
+ "! ".to_string(),
+ "!"
+ );
}
#[test]
fn test_varchararray_params() {
- test_array_params!("VARCHAR",
- "hello".to_string(),
- "hello",
- "world".to_string(),
- "world",
- "!".to_string(),
- "!");
+ test_array_params!(
+ "VARCHAR",
+ "hello".to_string(),
+ "hello",
+ "world".to_string(),
+ "world",
+ "!".to_string(),
+ "!"
+ );
}
#[test]
@@ -215,6 +238,11 @@ mod test {
fn test_empty_array() {
let conn = Connection::connect("postgres://postgres@localhost", TlsMode::None).unwrap();
let stmt = conn.prepare("SELECT '{}'::INT4[]").unwrap();
- stmt.query(&[]).unwrap().iter().next().unwrap().get::<_, Array>(0);
+ stmt.query(&[])
+ .unwrap()
+ .iter()
+ .next()
+ .unwrap()
+ .get::<_, Array>(0);
}
}
From d61d6544a1425cc2cd99d131ace968cd085b31c2 Mon Sep 17 00:00:00 2001
From: Steven Fackler
Date: Sun, 23 Jul 2017 13:37:48 -0700
Subject: [PATCH 04/14] Update to postgres 0.15
---
Cargo.toml | 5 ++++-
src/impls.rs | 2 +-
src/lib.rs | 5 ++++-
3 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/Cargo.toml b/Cargo.toml
index d7df5f5..83c8cf4 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -9,5 +9,8 @@ documentation = "https://docs.rs/postgres_array/0.8.0/postgres_array"
[dependencies]
fallible-iterator = "0.1"
-postgres = "0.14"
+postgres-shared = "0.4"
postgres-protocol = "0.3"
+
+[dev-dependencies]
+postgres = "0.15"
diff --git a/src/impls.rs b/src/impls.rs
index 841be0d..2bf4f15 100644
--- a/src/impls.rs
+++ b/src/impls.rs
@@ -1,5 +1,5 @@
use fallible_iterator::FallibleIterator;
-use postgres::types::{Type, Kind, ToSql, FromSql, IsNull};
+use postgres_shared::types::{Type, Kind, ToSql, FromSql, IsNull};
use postgres_protocol::types;
use postgres_protocol;
use std::error::Error;
diff --git a/src/lib.rs b/src/lib.rs
index 91f0b00..98ec34d 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -3,9 +3,12 @@
extern crate fallible_iterator;
#[macro_use]
-extern crate postgres;
+extern crate postgres_shared;
extern crate postgres_protocol;
+#[cfg(test)]
+extern crate postgres;
+
#[doc(inline)]
pub use array::Array;
From c6bcf583eaac0e916316364129382292bee07021 Mon Sep 17 00:00:00 2001
From: Steven Fackler
Date: Sun, 23 Jul 2017 13:42:32 -0700
Subject: [PATCH 05/14] Release v0.9.0
---
Cargo.toml | 4 ++--
src/lib.rs | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/Cargo.toml b/Cargo.toml
index 83c8cf4..b2481cc 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,11 +1,11 @@
[package]
name = "postgres_array"
-version = "0.8.0"
+version = "0.9.0"
authors = ["Steven Fackler "]
license = "MIT"
description = "Array support for rust-postgres"
repository = "https://github.com/sfackler/rust-postgres-array"
-documentation = "https://docs.rs/postgres_array/0.8.0/postgres_array"
+documentation = "https://docs.rs/postgres_array/0.9.0/postgres_array"
[dependencies]
fallible-iterator = "0.1"
diff --git a/src/lib.rs b/src/lib.rs
index 98ec34d..a4b29af 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,5 +1,5 @@
//! Multi-dimensional arrays with per-dimension specifiable lower bounds
-#![doc(html_root_url="https://docs.rs/postgres_array/0.8.0")]
+#![doc(html_root_url="https://docs.rs/postgres_array/0.9.0")]
extern crate fallible_iterator;
#[macro_use]
From 9c37388c9f4be75c3d77a4019c92019dcda5ae93 Mon Sep 17 00:00:00 2001
From: Steven Fackler
Date: Sun, 23 Jul 2017 13:44:23 -0700
Subject: [PATCH 06/14] Update readme
---
README.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 1ae0889..0008029 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# rust-postgres-array
-[](https://travis-ci.org/sfackler/rust-postgres-array)
+[](https://circleci.com/gh/sfackler/rust-postgres-array)
-[Documentation](https://sfackler.github.io/rust-postgres-array/doc/v0.7.1/postgres_array)
+[Documentation](https://docs.rs/postgres_array)
Support for PostgreSQL arrays in [rust-postgres](https://github.com/sfackler/rust-postgres).
From c68b66f93755c6b4f24470e9997252161854bf39 Mon Sep 17 00:00:00 2001
From: Steven Fackler
Date: Sun, 12 Jan 2020 16:05:52 -0800
Subject: [PATCH 07/14] Upgrade to 2018
---
Cargo.toml | 1 +
src/array.rs | 62 ++++++++++++++++++-----------------
src/impls.rs | 91 ++++++++++++++++++++++++++--------------------------
src/lib.rs | 24 ++++----------
4 files changed, 86 insertions(+), 92 deletions(-)
diff --git a/Cargo.toml b/Cargo.toml
index b2481cc..af06c0e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -2,6 +2,7 @@
name = "postgres_array"
version = "0.9.0"
authors = ["Steven Fackler "]
+edition = "2018"
license = "MIT"
description = "Array support for rust-postgres"
repository = "https://github.com/sfackler/rust-postgres-array"
diff --git a/src/array.rs b/src/array.rs
index 1cf85b3..3c030aa 100644
--- a/src/array.rs
+++ b/src/array.rs
@@ -1,9 +1,9 @@
+use std::fmt;
use std::ops::{Index, IndexMut};
use std::slice;
use std::vec;
-use std::fmt;
-use Dimension;
+use crate::Dimension;
/// A multi-dimensional array.
#[derive(Debug, PartialEq, Eq, Clone)]
@@ -13,17 +13,17 @@ pub struct Array {
}
impl fmt::Display for Array {
- fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+ fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.dims.iter().any(|dim| dim.lower_bound != 1) {
for dim in &self.dims {
- try!(write!(
+ write!(
fmt,
"[{}:{}]",
dim.lower_bound,
dim.lower_bound + dim.len - 1
- ));
+ )?;
}
- try!(write!(fmt, "="));
+ write!(fmt, "=")?;
}
fmt_helper(0, &self.dims, &mut self.data.iter(), fmt)
}
@@ -32,8 +32,8 @@ impl fmt::Display for Array {
fn fmt_helper<'a, T, I>(
depth: usize,
dims: &[Dimension],
- mut data: &mut I,
- fmt: &mut fmt::Formatter,
+ data: &mut I,
+ fmt: &mut fmt::Formatter<'_>,
) -> fmt::Result
where
I: Iterator
- ,
@@ -43,12 +43,12 @@ where
return write!(fmt, "{}", data.next().unwrap());
}
- try!(write!(fmt, "{{"));
+ write!(fmt, "{{")?;
for i in 0..dims[depth].len {
if i != 0 {
- try!(write!(fmt, ","));
+ write!(fmt, ",")?;
}
- try!(fmt_helper(depth + 1, dims, data, fmt));
+ fmt_helper(depth + 1, dims, data, fmt)?;
}
write!(fmt, "}}")
}
@@ -65,26 +65,24 @@ impl Array {
/// elements specified by the dimensions.
pub fn from_parts(data: Vec, dimensions: Vec) -> Array {
assert!(
- (data.is_empty() && dimensions.is_empty()) ||
- data.len() as i32 == dimensions.iter().fold(1, |acc, i| acc * i.len),
+ (data.is_empty() && dimensions.is_empty())
+ || data.len() as i32 == dimensions.iter().fold(1, |acc, i| acc * i.len),
"size mismatch"
);
Array {
dims: dimensions,
- data: data,
+ data,
}
}
/// Creates a new one-dimensional array.
pub fn from_vec(data: Vec, lower_bound: i32) -> Array {
Array {
- dims: vec![
- Dimension {
- len: data.len() as i32,
- lower_bound: lower_bound,
- },
- ],
- data: data,
+ dims: vec![Dimension {
+ len: data.len() as i32,
+ lower_bound,
+ }],
+ data,
}
}
@@ -97,7 +95,7 @@ impl Array {
0,
Dimension {
len: 1,
- lower_bound: lower_bound,
+ lower_bound,
},
);
}
@@ -147,14 +145,18 @@ impl Array {
/// Returns an iterator over references to the elements of the array in the
/// higher-dimensional equivalent of row-major order.
- pub fn iter<'a>(&'a self) -> Iter<'a, T> {
- Iter { inner: self.data.iter() }
+ pub fn iter(&self) -> Iter<'_, T> {
+ Iter {
+ inner: self.data.iter(),
+ }
}
/// Returns an iterator over mutable references to the elements of the
/// array in the higher-dimensional equivalent of row-major order.
- pub fn iter_mut<'a>(&'a mut self) -> IterMut<'a, T> {
- IterMut { inner: self.data.iter_mut() }
+ pub fn iter_mut(&mut self) -> IterMut<'_, T> {
+ IterMut {
+ inner: self.data.iter_mut(),
+ }
}
/// Returns the underlying data vector for this Array in the
@@ -293,13 +295,15 @@ impl IntoIterator for Array {
type IntoIter = IntoIter;
fn into_iter(self) -> IntoIter {
- IntoIter { inner: self.data.into_iter() }
+ IntoIter {
+ inner: self.data.into_iter(),
+ }
}
}
/// An iterator over references to values of an `Array` in the
/// higher-dimensional equivalent of row-major order.
-pub struct Iter<'a, T: 'a> {
+pub struct Iter<'a, T> {
inner: slice::Iter<'a, T>,
}
@@ -329,7 +333,7 @@ impl<'a, T: 'a> ExactSizeIterator for Iter<'a, T> {
/// An iterator over mutable references to values of an `Array` in the
/// higher-dimensional equivalent of row-major order.
-pub struct IterMut<'a, T: 'a> {
+pub struct IterMut<'a, T> {
inner: slice::IterMut<'a, T>,
}
diff --git a/src/impls.rs b/src/impls.rs
index 2bf4f15..cb7c013 100644
--- a/src/impls.rs
+++ b/src/impls.rs
@@ -1,41 +1,36 @@
use fallible_iterator::FallibleIterator;
-use postgres_shared::types::{Type, Kind, ToSql, FromSql, IsNull};
-use postgres_protocol::types;
use postgres_protocol;
+use postgres_protocol::types;
+use postgres_shared::to_sql_checked;
+use postgres_shared::types::{FromSql, IsNull, Kind, ToSql, Type};
use std::error::Error;
-use {Array, Dimension};
+use crate::{Array, Dimension};
impl FromSql for Array
where
T: FromSql,
{
- fn from_sql(ty: &Type, raw: &[u8]) -> Result, Box> {
+ fn from_sql(ty: &Type, raw: &[u8]) -> Result, Box> {
let element_type = match *ty.kind() {
Kind::Array(ref ty) => ty,
_ => unreachable!(),
};
- let array = try!(types::array_from_sql(raw));
-
- let dimensions = try!(
- array
- .dimensions()
- .map(|d| {
- Dimension {
- len: d.len,
- lower_bound: d.lower_bound,
- }
- })
- .collect()
- );
+ let array = types::array_from_sql(raw)?;
- let elements = try!(
- array
- .values()
- .and_then(|v| FromSql::from_sql_nullable(element_type, v))
- .collect()
- );
+ let dimensions = array
+ .dimensions()
+ .map(|d| Dimension {
+ len: d.len,
+ lower_bound: d.lower_bound,
+ })
+ .collect()?;
+
+ let elements = array
+ .values()
+ .and_then(|v| FromSql::from_sql_nullable(element_type, v))
+ .collect()?;
Ok(Array::from_parts(elements, dimensions))
}
@@ -52,21 +47,19 @@ impl ToSql for Array
where
T: ToSql,
{
- fn to_sql(&self, ty: &Type, w: &mut Vec) -> Result> {
+ fn to_sql(&self, ty: &Type, w: &mut Vec) -> Result> {
let element_type = match ty.kind() {
&Kind::Array(ref ty) => ty,
_ => unreachable!(),
};
- let dimensions = self.dimensions().iter().map(|d| {
- types::ArrayDimension {
- len: d.len,
- lower_bound: d.lower_bound,
- }
+ let dimensions = self.dimensions().iter().map(|d| types::ArrayDimension {
+ len: d.len,
+ lower_bound: d.lower_bound,
});
let elements = self.iter();
- try!(types::array_to_sql(
+ types::array_to_sql(
dimensions,
true,
element_type.oid(),
@@ -77,7 +70,7 @@ where
Err(e) => Err(e),
},
w,
- ));
+ )?;
Ok(IsNull::No)
}
@@ -96,18 +89,19 @@ where
mod test {
use std::fmt;
- use postgres::{Connection, TlsMode};
+ use crate::Array;
use postgres::types::{FromSql, ToSql};
- use Array;
+ use postgres::{Connection, TlsMode};
fn test_type(
sql_type: &str,
checks: &[(T, S)],
) {
- let conn = Connection::connect("postgres://postgres:password@localhost", TlsMode::None)
- .unwrap();
+ let conn =
+ Connection::connect("postgres://postgres:password@localhost", TlsMode::None).unwrap();
for &(ref val, ref repr) in checks.iter() {
- let stmt = conn.prepare(&format!("SELECT {}::{}", *repr, sql_type))
+ let stmt = conn
+ .prepare(&format!("SELECT {}::{}", *repr, sql_type))
.unwrap();
let result = stmt.query(&[]).unwrap().iter().next().unwrap().get(0);
assert!(val == &result);
@@ -119,19 +113,24 @@ mod test {
}
macro_rules! test_array_params {
- ($name:expr, $v1:expr, $s1:expr, $v2:expr, $s2:expr, $v3:expr, $s3:expr) => ({
-
- let tests = &[(Some(Array::from_vec(vec!(Some($v1), Some($v2), None), 1)),
- format!("'{{{},{},NULL}}'", $s1, $s2)),
- (None, "NULL".to_string())];
+ ($name:expr, $v1:expr, $s1:expr, $v2:expr, $s2:expr, $v3:expr, $s3:expr) => {{
+ let tests = &[
+ (
+ Some(Array::from_vec(vec![Some($v1), Some($v2), None], 1)),
+ format!("'{{{},{},NULL}}'", $s1, $s2),
+ ),
+ (None, "NULL".to_string()),
+ ];
test_type(&format!("{}[]", $name), tests);
- let mut a = Array::from_vec(vec!(Some($v1), Some($v2)), 0);
+ let mut a = Array::from_vec(vec![Some($v1), Some($v2)], 0);
a.wrap(-1);
- a.push(Array::from_vec(vec!(None, Some($v3)), 0));
- let tests = &[(Some(a), format!("'[-1:0][0:1]={{{{{},{}}},{{NULL,{}}}}}'",
- $s1, $s2, $s3))];
+ a.push(Array::from_vec(vec![None, Some($v3)], 0));
+ let tests = &[(
+ Some(a),
+ format!("'[-1:0][0:1]={{{{{},{}}},{{NULL,{}}}}}'", $s1, $s2, $s3),
+ )];
test_type(&format!("{}[][]", $name), tests);
- })
+ }};
}
#[test]
diff --git a/src/lib.rs b/src/lib.rs
index a4b29af..75357eb 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,16 +1,8 @@
//! Multi-dimensional arrays with per-dimension specifiable lower bounds
-#![doc(html_root_url="https://docs.rs/postgres_array/0.9.0")]
-
-extern crate fallible_iterator;
-#[macro_use]
-extern crate postgres_shared;
-extern crate postgres_protocol;
-
-#[cfg(test)]
-extern crate postgres;
+#![doc(html_root_url = "https://docs.rs/postgres_array/0.9.0")]
#[doc(inline)]
-pub use array::Array;
+pub use crate::array::Array;
pub mod array;
mod impls;
@@ -47,13 +39,11 @@ mod tests {
fn test_from_vec() {
let a = Array::from_vec(vec![0i32, 1, 2], -1);
assert!(
- &[
- Dimension {
- len: 3,
- lower_bound: -1,
- },
- ]
- [..] == a.dimensions()
+ &[Dimension {
+ len: 3,
+ lower_bound: -1,
+ },][..]
+ == a.dimensions()
);
assert_eq!(0, a[-1]);
assert_eq!(1, a[0]);
From a2f4b5c29dae81a02a6b25f4da58587a58bbf33f Mon Sep 17 00:00:00 2001
From: Steven Fackler
Date: Sun, 12 Jan 2020 16:20:51 -0800
Subject: [PATCH 08/14] Upgrade to new postgres version
---
Cargo.toml | 9 +++++----
circle.yml | 13 ++++++------
src/impls.rs | 56 ++++++++++++++++++++++++----------------------------
3 files changed, 37 insertions(+), 41 deletions(-)
diff --git a/Cargo.toml b/Cargo.toml
index af06c0e..6721ca1 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -9,9 +9,10 @@ repository = "https://github.com/sfackler/rust-postgres-array"
documentation = "https://docs.rs/postgres_array/0.9.0/postgres_array"
[dependencies]
-fallible-iterator = "0.1"
-postgres-shared = "0.4"
-postgres-protocol = "0.3"
+bytes = "0.5"
+fallible-iterator = "0.2"
+postgres-types = "0.1"
+postgres-protocol = "0.5"
[dev-dependencies]
-postgres = "0.15"
+postgres = "0.17"
diff --git a/circle.yml b/circle.yml
index a648ab0..290a005 100644
--- a/circle.yml
+++ b/circle.yml
@@ -1,10 +1,9 @@
version: 2
jobs:
build:
- working_directory: ~/build
docker:
- - image: jimmycuadra/rust:1.19.0
- - image: postgres:9.6
+ - image: rust:1.40.0
+ - image: postgres:12
environment:
POSTGRES_PASSWORD: password
steps:
@@ -15,12 +14,12 @@ jobs:
- save_cache:
key: registry-{{ epoch }}
paths:
- - ~/.cargo/registry/index
+ - /usr/local/cargo/registry/index
- restore_cache:
- key: dependencies-1.19-{{ checksum "Cargo.lock" }}
+ key: dependencies-1.40-{{ checksum "Cargo.lock" }}
- run: cargo test
- save_cache:
- key: dependencies-1.19-{{ checksum "Cargo.lock" }}
+ key: dependencies-1.40-{{ checksum "Cargo.lock" }}
paths:
- target
- - ~/.cargo/registry/cache
+ - /usr/local/cargo/registry/cache
diff --git a/src/impls.rs b/src/impls.rs
index cb7c013..399a36e 100644
--- a/src/impls.rs
+++ b/src/impls.rs
@@ -1,17 +1,17 @@
use fallible_iterator::FallibleIterator;
use postgres_protocol;
use postgres_protocol::types;
-use postgres_shared::to_sql_checked;
-use postgres_shared::types::{FromSql, IsNull, Kind, ToSql, Type};
+use postgres_types::{to_sql_checked, FromSql, IsNull, Kind, ToSql, Type};
use std::error::Error;
use crate::{Array, Dimension};
+use postgres_types::private::BytesMut;
-impl FromSql for Array
+impl<'de, T> FromSql<'de> for Array
where
- T: FromSql,
+ T: FromSql<'de>,
{
- fn from_sql(ty: &Type, raw: &[u8]) -> Result, Box> {
+ fn from_sql(ty: &Type, raw: &'de [u8]) -> Result, Box> {
let element_type = match *ty.kind() {
Kind::Array(ref ty) => ty,
_ => unreachable!(),
@@ -21,15 +21,17 @@ where
let dimensions = array
.dimensions()
- .map(|d| Dimension {
- len: d.len,
- lower_bound: d.lower_bound,
+ .map(|d| {
+ Ok(Dimension {
+ len: d.len,
+ lower_bound: d.lower_bound,
+ })
})
.collect()?;
let elements = array
.values()
- .and_then(|v| FromSql::from_sql_nullable(element_type, v))
+ .map(|v| FromSql::from_sql_nullable(element_type, v))
.collect()?;
Ok(Array::from_parts(elements, dimensions))
@@ -47,7 +49,7 @@ impl ToSql for Array
where
T: ToSql,
{
- fn to_sql(&self, ty: &Type, w: &mut Vec) -> Result> {
+ fn to_sql(&self, ty: &Type, w: &mut BytesMut) -> Result> {
let element_type = match ty.kind() {
&Kind::Array(ref ty) => ty,
_ => unreachable!(),
@@ -61,7 +63,6 @@ where
types::array_to_sql(
dimensions,
- true,
element_type.oid(),
elements,
|v, w| match v.to_sql(element_type, w) {
@@ -90,24 +91,25 @@ mod test {
use std::fmt;
use crate::Array;
- use postgres::types::{FromSql, ToSql};
- use postgres::{Connection, TlsMode};
+ use postgres::types::{FromSqlOwned, ToSql};
+ use postgres::{Client, NoTls};
- fn test_type(
+ fn test_type(
sql_type: &str,
checks: &[(T, S)],
) {
- let conn =
- Connection::connect("postgres://postgres:password@localhost", TlsMode::None).unwrap();
+ let mut conn = Client::connect("postgres://postgres:password@localhost", NoTls).unwrap();
for &(ref val, ref repr) in checks.iter() {
- let stmt = conn
- .prepare(&format!("SELECT {}::{}", *repr, sql_type))
- .unwrap();
- let result = stmt.query(&[]).unwrap().iter().next().unwrap().get(0);
+ let result = conn
+ .query(&*format!("SELECT {}::{}", *repr, sql_type), &[])
+ .unwrap()[0]
+ .get(0);
assert!(val == &result);
- let stmt = conn.prepare(&format!("SELECT $1::{}", sql_type)).unwrap();
- let result = stmt.query(&[val]).unwrap().iter().next().unwrap().get(0);
+ let result = conn
+ .query(&*format!("SELECT $1::{}", sql_type), &[val])
+ .unwrap()[0]
+ .get(0);
assert!(val == &result);
}
}
@@ -235,13 +237,7 @@ mod test {
#[test]
fn test_empty_array() {
- let conn = Connection::connect("postgres://postgres@localhost", TlsMode::None).unwrap();
- let stmt = conn.prepare("SELECT '{}'::INT4[]").unwrap();
- stmt.query(&[])
- .unwrap()
- .iter()
- .next()
- .unwrap()
- .get::<_, Array>(0);
+ let mut conn = Client::connect("postgres://postgres@localhost", NoTls).unwrap();
+ conn.query("SELECT '{}'::INT4[]", &[]).unwrap()[0].get::<_, Array>(0);
}
}
From c7d3f31f9f2bfbc8155a52c6a75f4687eef6c3cd Mon Sep 17 00:00:00 2001
From: Steven Fackler
Date: Sun, 12 Jan 2020 16:25:06 -0800
Subject: [PATCH 09/14] Release v0.10.0
---
Cargo.toml | 3 +--
src/lib.rs | 2 +-
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/Cargo.toml b/Cargo.toml
index 6721ca1..ed1be43 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,12 +1,11 @@
[package]
name = "postgres_array"
-version = "0.9.0"
+version = "0.10.0"
authors = ["Steven Fackler "]
edition = "2018"
license = "MIT"
description = "Array support for rust-postgres"
repository = "https://github.com/sfackler/rust-postgres-array"
-documentation = "https://docs.rs/postgres_array/0.9.0/postgres_array"
[dependencies]
bytes = "0.5"
diff --git a/src/lib.rs b/src/lib.rs
index 75357eb..a326a53 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,5 +1,5 @@
//! Multi-dimensional arrays with per-dimension specifiable lower bounds
-#![doc(html_root_url = "https://docs.rs/postgres_array/0.9.0")]
+#![doc(html_root_url = "https://docs.rs/postgres_array/0.10")]
#[doc(inline)]
pub use crate::array::Array;
From 014e740ae5c3c4bcb6bfae8b8790eb4e73be9f32 Mon Sep 17 00:00:00 2001
From: Nikhil Benesch
Date: Wed, 6 Jan 2021 01:06:33 -0500
Subject: [PATCH 10/14] Upgrade to new postgres version
---
Cargo.toml | 8 ++++----
circle.yml | 2 +-
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/Cargo.toml b/Cargo.toml
index ed1be43..e0e9682 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -8,10 +8,10 @@ description = "Array support for rust-postgres"
repository = "https://github.com/sfackler/rust-postgres-array"
[dependencies]
-bytes = "0.5"
+bytes = "1.0"
fallible-iterator = "0.2"
-postgres-types = "0.1"
-postgres-protocol = "0.5"
+postgres-types = "0.2"
+postgres-protocol = "0.6"
[dev-dependencies]
-postgres = "0.17"
+postgres = "0.19"
diff --git a/circle.yml b/circle.yml
index 290a005..23f9e02 100644
--- a/circle.yml
+++ b/circle.yml
@@ -2,7 +2,7 @@ version: 2
jobs:
build:
docker:
- - image: rust:1.40.0
+ - image: rust:1.45.0
- image: postgres:12
environment:
POSTGRES_PASSWORD: password
From fd0cac7df5e46dbe4e1364eebf28627e1a028353 Mon Sep 17 00:00:00 2001
From: Steven Fackler
Date: Wed, 6 Jan 2021 08:08:19 -0500
Subject: [PATCH 11/14] Release v0.11.0
---
Cargo.toml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Cargo.toml b/Cargo.toml
index e0e9682..c03eb0d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "postgres_array"
-version = "0.10.0"
+version = "0.11.0"
authors = ["Steven Fackler "]
edition = "2018"
license = "MIT"
From 00c305670b5537e0109547ab969d3e23fa8216d7 Mon Sep 17 00:00:00 2001
From: Joseph Koshakow
Date: Thu, 13 Oct 2022 18:43:27 -0400
Subject: [PATCH 12/14] Fix display for 0 dimensional arrays
---
src/array.rs | 4 ++++
src/lib.rs | 3 +++
2 files changed, 7 insertions(+)
diff --git a/src/array.rs b/src/array.rs
index 3c030aa..9886d8d 100644
--- a/src/array.rs
+++ b/src/array.rs
@@ -39,6 +39,10 @@ where
I: Iterator
- ,
T: 'a + fmt::Display,
{
+ if dims.len() == 0 {
+ return write!(fmt, "{{}}");
+ }
+
if depth == dims.len() {
return write!(fmt, "{}", data.next().unwrap());
}
diff --git a/src/lib.rs b/src/lib.rs
index a326a53..21240da 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -146,5 +146,8 @@ mod tests {
a.push(Array::from_vec(vec![4, 5, 6], 3));
a.wrap(1);
assert_eq!("[1:1][-2:-1][3:5]={{{1,2,3},{4,5,6}}}", &format!("{}", a));
+
+ let a: Array = Array::from_parts(vec![], vec![]);
+ assert_eq!("{}", &format!("{}", a));
}
}
From 830bd609dda5a0d7e49256e2d059a9a6a2fedd4e Mon Sep 17 00:00:00 2001
From: Steven Fackler
Date: Sun, 16 Oct 2022 20:55:41 -0400
Subject: [PATCH 13/14] bump ci version
---
circle.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/circle.yml b/circle.yml
index 23f9e02..8e1b563 100644
--- a/circle.yml
+++ b/circle.yml
@@ -2,7 +2,7 @@ version: 2
jobs:
build:
docker:
- - image: rust:1.45.0
+ - image: rust:1.64.0
- image: postgres:12
environment:
POSTGRES_PASSWORD: password
From a3b83ff88e848167364c0c797af9e9c487b7ed95 Mon Sep 17 00:00:00 2001
From: Steven Fackler
Date: Sun, 16 Oct 2022 20:59:08 -0400
Subject: [PATCH 14/14] Release v0.11.1
---
Cargo.toml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Cargo.toml b/Cargo.toml
index c03eb0d..5fa0f65 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "postgres_array"
-version = "0.11.0"
+version = "0.11.1"
authors = ["Steven Fackler "]
edition = "2018"
license = "MIT"
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