Rename optional crate imports

This commit is contained in:
Steven Fackler 2018-12-08 18:01:03 -08:00
parent 6ff59acdd2
commit 69a016fd85
9 changed files with 64 additions and 64 deletions

View File

@ -5,7 +5,7 @@ use std::fs::File;
use std::io::{BufWriter, Write};
use std::path::Path;
use snake_to_camel;
use crate::snake_to_camel;
const PG_TYPE_H: &'static str = include_str!("pg_type.h");
const PG_RANGE_H: &'static str = include_str!("pg_range.h");

View File

@ -24,12 +24,12 @@ features = [
circle-ci = { repository = "sfackler/rust-postgres" }
[features]
"with-bit-vec-0.5" = ["bit-vec"]
"with-chrono-0.4" = ["chrono"]
"with-eui48-0.3" = ["eui48"]
"with-geo-0.10" = ["geo"]
with-serde_json-1 = ["serde", "serde_json"]
"with-uuid-0.6" = ["uuid"]
"with-bit-vec-0.5" = ["bit-vec-05"]
"with-chrono-0.4" = ["chrono-04"]
"with-eui48-0.3" = ["eui48-03"]
"with-geo-0.10" = ["geo-010"]
with-serde_json-1 = ["serde-1", "serde_json-1"]
"with-uuid-0.6" = ["uuid-06"]
[dependencies]
antidote = "1.0"
@ -45,13 +45,13 @@ tokio-codec = "0.1"
tokio-io = "0.1"
void = "1.0"
bit-vec = { version = "0.5", optional = true }
chrono = { version = "0.4", optional = true }
eui48 = { version = "0.3", optional = true }
geo = { version = "0.10", optional = true }
serde = { version = "1.0", optional = true }
serde_json = { version = "1.0", optional = true }
uuid = { version = "0.6", optional = true }
bit-vec-05 = { version = "0.5", package = "bit-vec", optional = true }
chrono-04 = { version = "0.4", package = "chrono", optional = true }
eui48-03 = { version = "0.3", package = "eui48", optional = true }
geo-010 = { version = "0.10", package = "geo", optional = true }
serde-1 = { version = "1.0", package = "serde", optional = true }
serde_json-1 = { version = "1.0", package = "serde_json", optional = true }
uuid-06 = { version = "0.6", package = "uuid", optional = true }
[dev-dependencies]
tokio = "0.1.7"

View File

@ -1,11 +1,11 @@
use bit_vec::BitVec;
use bit_vec_05::BitVec;
use postgres_protocol::types;
use std::error::Error;
use types::{FromSql, IsNull, ToSql, Type};
use crate::types::{FromSql, IsNull, ToSql, Type};
impl<'a> FromSql<'a> for BitVec {
fn from_sql(_: &Type, raw: &[u8]) -> Result<BitVec, Box<Error + Sync + Send>> {
fn from_sql(_: &Type, raw: &[u8]) -> Result<BitVec, Box<dyn Error + Sync + Send>> {
let varbit = types::varbit_from_sql(raw)?;
let mut bitvec = BitVec::from_bytes(varbit.bytes());
while bitvec.len() > varbit.len() {
@ -19,7 +19,7 @@ impl<'a> FromSql<'a> for BitVec {
}
impl ToSql for BitVec {
fn to_sql(&self, _: &Type, out: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>> {
fn to_sql(&self, _: &Type, out: &mut Vec<u8>) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
types::varbit_to_sql(self.len(), self.to_bytes().into_iter(), out)?;
Ok(IsNull::No)
}

View File

@ -1,15 +1,15 @@
use chrono::{DateTime, Duration, FixedOffset, Local, NaiveDate, NaiveDateTime, NaiveTime, Utc};
use chrono_04::{DateTime, Duration, FixedOffset, Local, NaiveDate, NaiveDateTime, NaiveTime, Utc};
use postgres_protocol::types;
use std::error::Error;
use types::{FromSql, IsNull, ToSql, Type};
use crate::types::{FromSql, IsNull, ToSql, Type};
fn base() -> NaiveDateTime {
NaiveDate::from_ymd(2000, 1, 1).and_hms(0, 0, 0)
}
impl<'a> FromSql<'a> for NaiveDateTime {
fn from_sql(_: &Type, raw: &[u8]) -> Result<NaiveDateTime, Box<Error + Sync + Send>> {
fn from_sql(_: &Type, raw: &[u8]) -> Result<NaiveDateTime, Box<dyn Error + Sync + Send>> {
let t = types::timestamp_from_sql(raw)?;
Ok(base() + Duration::microseconds(t))
}
@ -18,7 +18,7 @@ impl<'a> FromSql<'a> for NaiveDateTime {
}
impl ToSql for NaiveDateTime {
fn to_sql(&self, _: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>> {
fn to_sql(&self, _: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
let time = match self.signed_duration_since(base()).num_microseconds() {
Some(time) => time,
None => return Err("value too large to transmit".into()),
@ -32,7 +32,7 @@ impl ToSql for NaiveDateTime {
}
impl<'a> FromSql<'a> for DateTime<Utc> {
fn from_sql(type_: &Type, raw: &[u8]) -> Result<DateTime<Utc>, Box<Error + Sync + Send>> {
fn from_sql(type_: &Type, raw: &[u8]) -> Result<DateTime<Utc>, Box<dyn Error + Sync + Send>> {
let naive = NaiveDateTime::from_sql(type_, raw)?;
Ok(DateTime::from_utc(naive, Utc))
}
@ -41,7 +41,7 @@ impl<'a> FromSql<'a> for DateTime<Utc> {
}
impl ToSql for DateTime<Utc> {
fn to_sql(&self, type_: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>> {
fn to_sql(&self, type_: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
self.naive_utc().to_sql(type_, w)
}
@ -50,7 +50,7 @@ impl ToSql for DateTime<Utc> {
}
impl<'a> FromSql<'a> for DateTime<Local> {
fn from_sql(type_: &Type, raw: &[u8]) -> Result<DateTime<Local>, Box<Error + Sync + Send>> {
fn from_sql(type_: &Type, raw: &[u8]) -> Result<DateTime<Local>, Box<dyn Error + Sync + Send>> {
let utc = DateTime::<Utc>::from_sql(type_, raw)?;
Ok(utc.with_timezone(&Local))
}
@ -59,7 +59,7 @@ impl<'a> FromSql<'a> for DateTime<Local> {
}
impl ToSql for DateTime<Local> {
fn to_sql(&self, type_: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>> {
fn to_sql(&self, type_: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
self.with_timezone(&Utc).to_sql(type_, w)
}
@ -71,7 +71,7 @@ impl<'a> FromSql<'a> for DateTime<FixedOffset> {
fn from_sql(
type_: &Type,
raw: &[u8],
) -> Result<DateTime<FixedOffset>, Box<Error + Sync + Send>> {
) -> Result<DateTime<FixedOffset>, Box<dyn Error + Sync + Send>> {
let utc = DateTime::<Utc>::from_sql(type_, raw)?;
Ok(utc.with_timezone(&FixedOffset::east(0)))
}
@ -80,7 +80,7 @@ impl<'a> FromSql<'a> for DateTime<FixedOffset> {
}
impl ToSql for DateTime<FixedOffset> {
fn to_sql(&self, type_: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>> {
fn to_sql(&self, type_: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
self.with_timezone(&Utc).to_sql(type_, w)
}
@ -89,7 +89,7 @@ impl ToSql for DateTime<FixedOffset> {
}
impl<'a> FromSql<'a> for NaiveDate {
fn from_sql(_: &Type, raw: &[u8]) -> Result<NaiveDate, Box<Error + Sync + Send>> {
fn from_sql(_: &Type, raw: &[u8]) -> Result<NaiveDate, Box<dyn Error + Sync + Send>> {
let jd = types::date_from_sql(raw)?;
Ok(base().date() + Duration::days(jd as i64))
}
@ -98,7 +98,7 @@ impl<'a> FromSql<'a> for NaiveDate {
}
impl ToSql for NaiveDate {
fn to_sql(&self, _: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>> {
fn to_sql(&self, _: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
let jd = self.signed_duration_since(base().date()).num_days();
if jd > i32::max_value() as i64 || jd < i32::min_value() as i64 {
return Err("value too large to transmit".into());
@ -113,7 +113,7 @@ impl ToSql for NaiveDate {
}
impl<'a> FromSql<'a> for NaiveTime {
fn from_sql(_: &Type, raw: &[u8]) -> Result<NaiveTime, Box<Error + Sync + Send>> {
fn from_sql(_: &Type, raw: &[u8]) -> Result<NaiveTime, Box<dyn Error + Sync + Send>> {
let usec = types::time_from_sql(raw)?;
Ok(NaiveTime::from_hms(0, 0, 0) + Duration::microseconds(usec))
}
@ -122,7 +122,7 @@ impl<'a> FromSql<'a> for NaiveTime {
}
impl ToSql for NaiveTime {
fn to_sql(&self, _: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>> {
fn to_sql(&self, _: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
let delta = self.signed_duration_since(NaiveTime::from_hms(0, 0, 0));
let time = match delta.num_microseconds() {
Some(time) => time,

View File

@ -1,11 +1,11 @@
use eui48::MacAddress;
use eui48_03::MacAddress;
use postgres_protocol::types;
use std::error::Error;
use types::{FromSql, IsNull, ToSql, Type};
use crate::types::{FromSql, IsNull, ToSql, Type};
impl<'a> FromSql<'a> for MacAddress {
fn from_sql(_: &Type, raw: &[u8]) -> Result<MacAddress, Box<Error + Sync + Send>> {
fn from_sql(_: &Type, raw: &[u8]) -> Result<MacAddress, Box<dyn Error + Sync + Send>> {
let bytes = types::macaddr_from_sql(raw)?;
Ok(MacAddress::new(bytes))
}
@ -14,7 +14,7 @@ impl<'a> FromSql<'a> for MacAddress {
}
impl ToSql for MacAddress {
fn to_sql(&self, _: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>> {
fn to_sql(&self, _: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
let mut bytes = [0; 6];
bytes.copy_from_slice(self.as_bytes());
types::macaddr_to_sql(bytes, w);

View File

@ -1,12 +1,12 @@
use fallible_iterator::FallibleIterator;
use geo::{Coordinate, LineString, Point, Rect};
use geo_010::{Coordinate, LineString, Point, Rect};
use postgres_protocol::types;
use std::error::Error;
use types::{FromSql, IsNull, ToSql, Type};
use crate::types::{FromSql, IsNull, ToSql, Type};
impl<'a> FromSql<'a> for Point<f64> {
fn from_sql(_: &Type, raw: &[u8]) -> Result<Self, Box<Error + Sync + Send>> {
fn from_sql(_: &Type, raw: &[u8]) -> Result<Self, Box<dyn Error + Sync + Send>> {
let point = types::point_from_sql(raw)?;
Ok(Point::new(point.x(), point.y()))
}
@ -15,7 +15,7 @@ impl<'a> FromSql<'a> for Point<f64> {
}
impl ToSql for Point<f64> {
fn to_sql(&self, _: &Type, out: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>> {
fn to_sql(&self, _: &Type, out: &mut Vec<u8>) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
types::point_to_sql(self.x(), self.y(), out);
Ok(IsNull::No)
}
@ -25,7 +25,7 @@ impl ToSql for Point<f64> {
}
impl<'a> FromSql<'a> for Rect<f64> {
fn from_sql(_: &Type, raw: &[u8]) -> Result<Self, Box<Error + Sync + Send>> {
fn from_sql(_: &Type, raw: &[u8]) -> Result<Self, Box<dyn Error + Sync + Send>> {
let rect = types::box_from_sql(raw)?;
Ok(Rect {
min: Coordinate {
@ -43,7 +43,7 @@ impl<'a> FromSql<'a> for Rect<f64> {
}
impl ToSql for Rect<f64> {
fn to_sql(&self, _: &Type, out: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>> {
fn to_sql(&self, _: &Type, out: &mut Vec<u8>) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
types::box_to_sql(self.min.x, self.min.y, self.max.x, self.max.y, out);
Ok(IsNull::No)
}
@ -53,7 +53,7 @@ impl ToSql for Rect<f64> {
}
impl<'a> FromSql<'a> for LineString<f64> {
fn from_sql(_: &Type, raw: &[u8]) -> Result<Self, Box<Error + Sync + Send>> {
fn from_sql(_: &Type, raw: &[u8]) -> Result<Self, Box<dyn Error + Sync + Send>> {
let path = types::path_from_sql(raw)?;
let points = path
.points()
@ -66,7 +66,7 @@ impl<'a> FromSql<'a> for LineString<f64> {
}
impl ToSql for LineString<f64> {
fn to_sql(&self, _: &Type, out: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>> {
fn to_sql(&self, _: &Type, out: &mut Vec<u8>) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
let closed = false; // always encode an open path from LineString
types::path_to_sql(closed, self.0.iter().map(|p| (p.x, p.y)), out)?;
Ok(IsNull::No)

View File

@ -72,23 +72,23 @@ where
}
#[cfg(feature = "with-bit-vec-0.5")]
mod bit_vec;
mod bit_vec_05;
#[cfg(feature = "with-chrono-0.4")]
mod chrono;
mod chrono_04;
#[cfg(feature = "with-eui48-0.3")]
mod eui48;
mod eui48_03;
#[cfg(feature = "with-geo-0.10")]
mod geo;
mod geo_010;
#[cfg(feature = "with-serde_json-1")]
mod serde_json;
mod serde_json_1;
#[cfg(feature = "with-uuid-0.6")]
mod uuid;
mod uuid_06;
mod special;
mod type_gen;
#[cfg(feature = "with-serde_json-1")]
pub use self::serde_json::Json;
pub use crate::types::serde_json_1::Json;
/// A Postgres type.
#[derive(PartialEq, Eq, Clone, Debug)]

View File

@ -1,10 +1,10 @@
use serde::{Deserialize, Serialize};
use serde_json::Value;
use serde_1::{Deserialize, Serialize};
use serde_json_1::Value;
use std::error::Error;
use std::fmt::Debug;
use std::io::Read;
use types::{FromSql, IsNull, ToSql, Type};
use crate::types::{FromSql, IsNull, ToSql, Type};
#[derive(Debug)]
pub struct Json<T>(pub T);
@ -13,7 +13,7 @@ impl<'a, T> FromSql<'a> for Json<T>
where
T: Deserialize<'a>,
{
fn from_sql(ty: &Type, mut raw: &'a [u8]) -> Result<Json<T>, Box<Error + Sync + Send>> {
fn from_sql(ty: &Type, mut raw: &'a [u8]) -> Result<Json<T>, Box<dyn Error + Sync + Send>> {
if *ty == Type::JSONB {
let mut b = [0; 1];
raw.read_exact(&mut b)?;
@ -22,7 +22,7 @@ where
return Err("unsupported JSONB encoding version".into());
}
}
serde_json::de::from_slice(raw)
serde_json_1::de::from_slice(raw)
.map(Json)
.map_err(Into::into)
}
@ -34,11 +34,11 @@ impl<T> ToSql for Json<T>
where
T: Serialize + Debug,
{
fn to_sql(&self, ty: &Type, out: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>> {
fn to_sql(&self, ty: &Type, out: &mut Vec<u8>) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
if *ty == Type::JSONB {
out.push(1);
}
serde_json::ser::to_writer(out, &self.0)?;
serde_json_1::ser::to_writer(out, &self.0)?;
Ok(IsNull::No)
}
@ -47,7 +47,7 @@ where
}
impl<'a> FromSql<'a> for Value {
fn from_sql(ty: &Type, raw: &[u8]) -> Result<Value, Box<Error + Sync + Send>> {
fn from_sql(ty: &Type, raw: &[u8]) -> Result<Value, Box<dyn Error + Sync + Send>> {
Json::<Value>::from_sql(ty, raw).map(|json| json.0)
}
@ -55,7 +55,7 @@ impl<'a> FromSql<'a> for Value {
}
impl ToSql for Value {
fn to_sql(&self, ty: &Type, out: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>> {
fn to_sql(&self, ty: &Type, out: &mut Vec<u8>) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
Json(self).to_sql(ty, out)
}

View File

@ -1,11 +1,11 @@
use postgres_protocol::types;
use std::error::Error;
use uuid::Uuid;
use uuid_06::Uuid;
use types::{FromSql, IsNull, ToSql, Type};
use crate::types::{FromSql, IsNull, ToSql, Type};
impl<'a> FromSql<'a> for Uuid {
fn from_sql(_: &Type, raw: &[u8]) -> Result<Uuid, Box<Error + Sync + Send>> {
fn from_sql(_: &Type, raw: &[u8]) -> Result<Uuid, Box<dyn Error + Sync + Send>> {
let bytes = types::uuid_from_sql(raw)?;
Ok(Uuid::from_bytes(&bytes).unwrap())
}
@ -14,7 +14,7 @@ impl<'a> FromSql<'a> for Uuid {
}
impl ToSql for Uuid {
fn to_sql(&self, _: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>> {
fn to_sql(&self, _: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
types::uuid_to_sql(*self.as_bytes(), w);
Ok(IsNull::No)
}