diff options
author | Till Höppner | 2016-02-18 19:08:29 +0100 |
---|---|---|
committer | Till Höppner | 2016-02-18 19:08:29 +0100 |
commit | cf5c804fb38df114c75b37878d5703d67402ef89 (patch) | |
tree | 0211e5378d874ddf8bd1f486420514c7016e37e7 /lib | |
parent | aea35fa7e1a3261e5e7a3e8daa999bed3dcd193f (diff) | |
download | includedir-cf5c804fb38df114c75b37878d5703d67402ef89.tar.gz includedir-cf5c804fb38df114c75b37878d5703d67402ef89.tar.xz includedir-cf5c804fb38df114c75b37878d5703d67402ef89.zip |
Make flate2 dependency optional
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Cargo.toml | 2 | ||||
-rw-r--r-- | lib/src/lib.rs | 9 |
2 files changed, 10 insertions, 1 deletions
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")), |