Skip to content

Commit

Permalink
feature gate for datetime support - 2nd part
Browse files Browse the repository at this point in the history
  • Loading branch information
nmandery committed Feb 12, 2020
1 parent e8115ae commit 2952106
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ documentation = "https://georust.github.io/gdal/"
bindgen = ["gdal-sys/bindgen"]
gdal_2_2 = ["gdal-sys/min_gdal_version_2_2"]
array = ["ndarray"]
datetime = ["chrono"]

[dependencies]
failure = "0.1"
Expand All @@ -24,7 +25,7 @@ geo-types = "0.4"
gdal-sys = "0.2"
num-traits = "0.2"
ndarray = {version = "0.12.1", optional = true }
chrono = "0.4"
chrono = { version = "0.4", optional = true }

[workspace]
members = ["gdal-sys"]
13 changes: 13 additions & 0 deletions examples/read_write_ogr_datetime.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@

extern crate gdal;
#[cfg(feature = "datetime")]
extern crate chrono;

use std::path::Path;
use gdal::errors::Error;
use gdal::vector::*;
use std::fs;
#[cfg(feature = "datetime")]
use chrono::Duration;
use std::ops::Add;

#[cfg(feature = "datetime")]
fn run() -> Result<(), Error> {
println!("gdal crate was build with datetime support");

let mut dataset_a = Dataset::open(Path::new("fixtures/points_with_datetime.json"))?;
let layer_a = dataset_a.layer(0)?;

Expand Down Expand Up @@ -55,6 +61,13 @@ fn run() -> Result<(), Error> {
Ok(())
}

#[cfg(not(feature = "datetime"))]
fn run() -> Result<(), Error> {
println!("gdal crate was build without datetime support");
Ok(())
}


fn main() {
run().unwrap();
}
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ extern crate num_traits;

#[cfg(feature = "ndarray")]
extern crate ndarray;

#[cfg(feature = "datetime")]
extern crate chrono;

pub use version::version_info;
Expand Down

0 comments on commit 2952106

Please sign in to comment.