Fix feature gates
This commit is contained in:
parent
1268d66ca5
commit
cd89d6cec6
7
build.rs
7
build.rs
|
@ -4,7 +4,12 @@ fn main() {
|
||||||
println!("cargo:rerun-if-changed=wrapper.h");
|
println!("cargo:rerun-if-changed=wrapper.h");
|
||||||
println!("cargo:rerun-if-changed=lzokay/lzokay.cpp");
|
println!("cargo:rerun-if-changed=lzokay/lzokay.cpp");
|
||||||
println!("cargo:rerun-if-changed=lzokay/lzokay.hpp");
|
println!("cargo:rerun-if-changed=lzokay/lzokay.hpp");
|
||||||
cc::Build::new().cpp(true).file("lzokay/lzokay.cpp").compile("lzokay");
|
cc::Build::new()
|
||||||
|
.cpp(true)
|
||||||
|
.file("lzokay/lzokay.cpp")
|
||||||
|
.flag_if_supported("-std=c++14") // GCC/Clang
|
||||||
|
.flag_if_supported("/std:c++14") // MSVC
|
||||||
|
.compile("lzokay");
|
||||||
#[allow(unused_mut)]
|
#[allow(unused_mut)]
|
||||||
let mut bindings = bindgen::Builder::default()
|
let mut bindings = bindgen::Builder::default()
|
||||||
.header("wrapper.hpp")
|
.header("wrapper.hpp")
|
||||||
|
|
|
@ -11,8 +11,10 @@
|
||||||
//! use lzokay::compress::*;
|
//! use lzokay::compress::*;
|
||||||
//! # #[allow(non_upper_case_globals)] const input: [u8; 512] = [0u8; 512];
|
//! # #[allow(non_upper_case_globals)] const input: [u8; 512] = [0u8; 512];
|
||||||
//!
|
//!
|
||||||
|
//! # #[cfg(feature = "alloc")] {
|
||||||
//! let dst: Vec<u8> = compress(&input)?;
|
//! let dst: Vec<u8> = compress(&input)?;
|
||||||
//! # assert_eq!(dst.len(), 10);
|
//! # assert_eq!(dst.len(), 10);
|
||||||
|
//! # }
|
||||||
//! # Ok::<(), lzokay::Error>(())
|
//! # Ok::<(), lzokay::Error>(())
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
|
@ -22,11 +24,13 @@
|
||||||
//! # #[allow(non_upper_case_globals)] const input1: [u8; 512] = [0u8; 512];
|
//! # #[allow(non_upper_case_globals)] const input1: [u8; 512] = [0u8; 512];
|
||||||
//! # #[allow(non_upper_case_globals)] const input2: [u8; 512] = [0u8; 512];
|
//! # #[allow(non_upper_case_globals)] const input2: [u8; 512] = [0u8; 512];
|
||||||
//!
|
//!
|
||||||
|
//! # #[cfg(feature = "alloc")] {
|
||||||
//! let mut dict = new_dict();
|
//! let mut dict = new_dict();
|
||||||
//! let dst1 = compress_with_dict(&input1, &mut dict)?;
|
//! let dst1 = compress_with_dict(&input1, &mut dict)?;
|
||||||
//! let dst2 = compress_with_dict(&input2, &mut dict)?;
|
//! let dst2 = compress_with_dict(&input2, &mut dict)?;
|
||||||
//! # assert_eq!(dst1.len(), 10);
|
//! # assert_eq!(dst1.len(), 10);
|
||||||
//! # assert_eq!(dst2.len(), 10);
|
//! # assert_eq!(dst2.len(), 10);
|
||||||
|
//! # }
|
||||||
//! # Ok::<(), lzokay::Error>(())
|
//! # Ok::<(), lzokay::Error>(())
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
|
@ -55,7 +59,9 @@ use alloc::{
|
||||||
boxed::Box,
|
boxed::Box,
|
||||||
vec::Vec,
|
vec::Vec,
|
||||||
};
|
};
|
||||||
use core::{marker::PhantomData, mem::size_of, ptr::null_mut};
|
#[cfg(feature = "alloc")]
|
||||||
|
use core::ptr::null_mut;
|
||||||
|
use core::{marker::PhantomData, mem::size_of};
|
||||||
|
|
||||||
use crate::{bindings, lzokay_result, Error};
|
use crate::{bindings, lzokay_result, Error};
|
||||||
|
|
||||||
|
@ -98,6 +104,7 @@ pub fn dict_from_storage(storage: &mut [u8]) -> Dict {
|
||||||
}
|
}
|
||||||
Dict {
|
Dict {
|
||||||
base: bindings::lzokay_DictBase { _storage: storage.as_mut_ptr() as *mut DictStorage },
|
base: bindings::lzokay_DictBase { _storage: storage.as_mut_ptr() as *mut DictStorage },
|
||||||
|
#[cfg(feature = "alloc")]
|
||||||
storage: Option::None,
|
storage: Option::None,
|
||||||
phantom: PhantomData,
|
phantom: PhantomData,
|
||||||
}
|
}
|
||||||
|
|
13
src/lib.rs
13
src/lib.rs
|
@ -103,20 +103,17 @@ fn lzokay_result<T>(result: T, error: bindings::lzokay_EResult) -> Result<T, Err
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
#[cfg(all(feature = "compress", feature = "decompress", feature = "alloc"))]
|
||||||
mod tests {
|
mod tests {
|
||||||
#[cfg(all(not(feature = "std"), feature = "alloc"))]
|
#[cfg(not(feature = "std"))]
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
#[cfg(all(not(feature = "std"), feature = "alloc"))]
|
#[cfg(not(feature = "std"))]
|
||||||
use alloc::vec::Vec;
|
use alloc::vec;
|
||||||
|
|
||||||
#[cfg(all(feature = "compress", feature = "alloc"))]
|
use super::{compress::compress, decompress::decompress};
|
||||||
use super::compress::compress;
|
|
||||||
#[cfg(feature = "decompress")]
|
|
||||||
use super::decompress::decompress;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(all(feature = "compress", feature = "decompress", feature = "alloc"))]
|
|
||||||
fn test_round_trip() {
|
fn test_round_trip() {
|
||||||
let src = include_bytes!("test1.txt");
|
let src = include_bytes!("test1.txt");
|
||||||
let compressed = compress(src).expect("Failed to compress");
|
let compressed = compress(src).expect("Failed to compress");
|
||||||
|
|
Loading…
Reference in New Issue