Skip to content

Cleanup #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
11 changes: 7 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
6 changes: 5 additions & 1 deletion src/impls.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand All @@ -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");
}
Expand Down
18 changes: 13 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -149,6 +155,7 @@ macro_rules! bounded_normalizable {
bounded_normalizable!(i32);
bounded_normalizable!(i64);

#[cfg(feature = "with-time")]
impl Normalizable for Timespec {
fn normalize<S>(bound: RangeBound<S, Timespec>) -> RangeBound<S, Timespec>
where
Expand All @@ -158,7 +165,8 @@ impl Normalizable for Timespec {
}
}

impl<T> Normalizable for DateTime<T>
#[cfg(feature = "with-chrono")]
impl<T> Normalizable for DateTime<T>
where T: TimeZone {
fn normalize<S>(bound: RangeBound<S, DateTime<T>>) -> RangeBound<S, DateTime<T>>
where
Expand Down