Skip to content

Commit 28c8907

Browse files
committed
Make time and chrono dependencies optional
1 parent a37d984 commit 28c8907

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ addons:
77
postgresql: 9.4
88
script:
99
- cargo test
10+
- cargo test --features "with-time with-chrono"

Cargo.toml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ description = "Range support for rust-postgres"
77
repository = "https://github.com/sfackler/rust-postgres-range"
88
documentation = "https://sfackler.github.io/rust-postgres-range/doc/v0.9.0/postgres_range"
99

10+
[features]
11+
with-time = ["time", "postgres-shared/with-time"]
12+
with-chrono = ["chrono", "postgres-shared/with-chrono"]
13+
1014
[dependencies]
11-
time = "0.1"
15+
time = { version = "0.1", optional = true }
1216
postgres-protocol = "0.3"
13-
chrono = "0.4.0"
14-
postgres-shared = { version = "0.4.0", features = ["with-chrono"] }
17+
chrono = { version = "0.4.0", optional = true }
18+
postgres-shared = "0.4.0"
1519

1620
[dev-dependencies]
1721
postgres = { version = "0.15", features = ["with-time"] }

src/impls.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ mod test {
116116

117117
use postgres::{Connection, TlsMode};
118118
use postgres::types::{FromSql, ToSql};
119+
#[cfg(feature = "with-time")]
119120
use time::{self, Timespec};
120121

121122
macro_rules! test_range {
@@ -163,6 +164,7 @@ mod test {
163164
test_range!("INT8RANGE", i64, 100i64, "100", 200i64, "200")
164165
}
165166

167+
#[cfg(feature = "with-time")]
166168
fn test_timespec_range_params(sql_type: &str) {
167169
fn t(time: &str) -> Timespec {
168170
time::strptime(time, "%Y-%m-%d").unwrap().to_timespec()
@@ -173,11 +175,13 @@ mod test {
173175
}
174176

175177
#[test]
178+
#[cfg(feature = "with-time")]
176179
fn test_tsrange_params() {
177180
test_timespec_range_params("TSRANGE");
178181
}
179182

180183
#[test]
184+
#[cfg(feature = "with-time")]
181185
fn test_tstzrange_params() {
182186
test_timespec_range_params("TSTZRANGE");
183187
}

src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,23 @@
44
extern crate postgres_protocol;
55
#[macro_use(to_sql_checked)]
66
extern crate postgres_shared;
7+
8+
#[cfg(feature = "with-time")]
79
extern crate time;
10+
#[cfg(feature = "with-chrono")]
811
extern crate chrono;
912

1013
#[cfg(test)]
1114
extern crate postgres;
1215

16+
#[cfg(feature = "with-chrono")]
1317
use chrono::{DateTime, TimeZone};
1418
use std::cmp::Ordering;
1519
use std::fmt;
1620
use std::i32;
1721
use std::i64;
1822
use std::marker::PhantomData;
19-
23+
#[cfg(feature = "with-time")]
2024
use time::Timespec;
2125

2226
use BoundSide::{Lower, Upper};
@@ -151,6 +155,7 @@ macro_rules! bounded_normalizable {
151155
bounded_normalizable!(i32);
152156
bounded_normalizable!(i64);
153157

158+
#[cfg(feature = "with-time")]
154159
impl Normalizable for Timespec {
155160
fn normalize<S>(bound: RangeBound<S, Timespec>) -> RangeBound<S, Timespec>
156161
where
@@ -160,6 +165,7 @@ impl Normalizable for Timespec {
160165
}
161166
}
162167

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

0 commit comments

Comments
 (0)