From cf5c804fb38df114c75b37878d5703d67402ef89 Mon Sep 17 00:00:00 2001 From: Till Höppner Date: Thu, 18 Feb 2016 19:08:29 +0100 Subject: Make flate2 dependency optional --- example/Cargo.toml | 5 ++--- lib/Cargo.toml | 2 +- lib/src/lib.rs | 9 +++++++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/example/Cargo.toml b/example/Cargo.toml index 678f8fb..a3cd724 100644 --- a/example/Cargo.toml +++ b/example/Cargo.toml @@ -9,9 +9,8 @@ publish = false [dependencies] phf = "0.7.12" # includedir = "0.1.1" -includedir = { path = "../lib" } +includedir = { default-features = true, path = "../lib" } [build-dependencies] -# includedir = "0.1.1" -includedir = { path = "../lib" } +# includedir_codegen = "0.1.1" includedir_codegen = { path = "../codegen" } diff --git a/lib/Cargo.toml b/lib/Cargo.toml index aa82ad8..732ddd6 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -14,4 +14,4 @@ default = ["flate2"] [dependencies] phf = "0.7.12" -flate2 = { version = "*", optional = true } +flate2 = { version = "0.2.13", optional = true } diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 666c727..20078a2 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -1,9 +1,12 @@ extern crate phf; + +#[cfg(feature = "flate2")] extern crate flate2; use std::borrow::{Borrow, Cow}; use std::io::{self, Cursor, Error, ErrorKind, Read}; +#[cfg(feature = "flate2")] use flate2::FlateReadExt; pub enum Compression { @@ -38,12 +41,15 @@ impl Files { Some(b) => { match b.0 { Compression::None => Ok(Cow::Borrowed(b.1)), + #[cfg(feature = "flate2")] Compression::Gzip => { let mut r = try!(Cursor::new(b.1).gz_decode()); let mut v = Vec::new(); try!(r.read_to_end(&mut v)); Ok(Cow::Owned(v)) } + #[cfg(not(feature = "flate2"))] + Compression::Gzip => panic!("Feature 'flate2' not enabled"), } } None => Err(Error::new(ErrorKind::NotFound, "Key not found")), @@ -56,7 +62,10 @@ impl Files { Some(b) => { match b.0 { Compression::None => Ok(Box::new(Cursor::new(b.1))), + #[cfg(feature = "flate2")] Compression::Gzip => Ok(Box::new(try!(Cursor::new(b.1).gz_decode()))), + #[cfg(not(feature = "flate2"))] + Compression::Gzip => panic!("Feature 'flate2' not enabled"), } } None => Err(Error::new(ErrorKind::NotFound, "Key not found")), -- cgit v1.2.3