diff --git a/.travis.yml b/.travis.yml index ea999b2..b634ecd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,8 +2,9 @@ language: rust rust: - nightly - beta -- 1.20.0 +- 1.26.0 addons: postgresql: 9.4 script: - cargo test +- cargo test --features "with-time with-chrono" diff --git a/Cargo.toml b/Cargo.toml index 19e2ec8..01672fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,12 +7,15 @@ description = "Range support for rust-postgres" repository = "https://github.com/sfackler/rust-postgres-range" documentation = "https://sfackler.github.io/rust-postgres-range/doc/v0.9.0/postgres_range" +[features] +with-time = ["time", "postgres-shared/with-time"] +with-chrono = ["chrono", "postgres-shared/with-chrono"] + [dependencies] -time = "0.1" -postgres = "0.15" +time = { version = "0.1", optional = true } postgres-protocol = "0.3" -chrono = "0.4.0" -postgres-shared = { version = "0.4.0", features = ["with-chrono"] } +chrono = { version = "0.4.0", optional = true } +postgres-shared = "0.4.0" [dev-dependencies] postgres = { version = "0.15", features = ["with-time"] } diff --git a/src/impls.rs b/src/impls.rs index d7c6a76..567500f 100644 --- a/src/impls.rs +++ b/src/impls.rs @@ -1,5 +1,5 @@ use std::error::Error; -use postgres::types::{FromSql, IsNull, Kind, ToSql, Type}; +use postgres_shared::types::{FromSql, IsNull, Kind, ToSql, Type}; use postgres_protocol::{self as protocol, types}; use {BoundSided, BoundType, Normalizable, Range, RangeBound}; @@ -116,6 +116,7 @@ mod test { use postgres::{Connection, TlsMode}; use postgres::types::{FromSql, ToSql}; + #[cfg(feature = "with-time")] use time::{self, Timespec}; macro_rules! test_range { @@ -163,6 +164,7 @@ mod test { test_range!("INT8RANGE", i64, 100i64, "100", 200i64, "200") } + #[cfg(feature = "with-time")] fn test_timespec_range_params(sql_type: &str) { fn t(time: &str) -> Timespec { time::strptime(time, "%Y-%m-%d").unwrap().to_timespec() @@ -173,11 +175,13 @@ mod test { } #[test] + #[cfg(feature = "with-time")] fn test_tsrange_params() { test_timespec_range_params("TSRANGE"); } #[test] + #[cfg(feature = "with-time")] fn test_tstzrange_params() { test_timespec_range_params("TSTZRANGE"); } diff --git a/src/lib.rs b/src/lib.rs index 5b28546..a2178a3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,20 +1,26 @@ //! Types dealing with ranges of values #![doc(html_root_url = "https://sfackler.github.io/rust-postgres-range/doc/v0.8.2")] -#[macro_use(to_sql_checked)] -extern crate postgres; extern crate postgres_protocol; +#[macro_use(to_sql_checked)] extern crate postgres_shared; + +#[cfg(feature = "with-time")] extern crate time; +#[cfg(feature = "with-chrono")] extern crate chrono; -use chrono::{DateTime, TimeZone}; +#[cfg(test)] +extern crate postgres; + +#[cfg(feature = "with-chrono")] +use chrono::{DateTime, TimeZone}; use std::cmp::Ordering; use std::fmt; use std::i32; use std::i64; use std::marker::PhantomData; - +#[cfg(feature = "with-time")] use time::Timespec; use BoundSide::{Lower, Upper}; @@ -149,6 +155,7 @@ macro_rules! bounded_normalizable { bounded_normalizable!(i32); bounded_normalizable!(i64); +#[cfg(feature = "with-time")] impl Normalizable for Timespec { fn normalize(bound: RangeBound) -> RangeBound where @@ -158,7 +165,8 @@ impl Normalizable for Timespec { } } -impl Normalizable for DateTime +#[cfg(feature = "with-chrono")] +impl Normalizable for DateTime where T: TimeZone { fn normalize(bound: RangeBound>) -> RangeBound> where