diff --git a/examples/game_of_life/src/main.rs b/examples/game_of_life/src/main.rs index 40e6901..4f04464 100644 --- a/examples/game_of_life/src/main.rs +++ b/examples/game_of_life/src/main.rs @@ -26,7 +26,7 @@ fn main() { Command::BitmapLinearWin( Origin(0, 0), field.clone(), - CompressionCode::Bzip2, + CompressionCode::Lzma, ) .into(), ) diff --git a/servicepoint2/Cargo.toml b/servicepoint2/Cargo.toml index d0b985a..700b666 100644 --- a/servicepoint2/Cargo.toml +++ b/servicepoint2/Cargo.toml @@ -20,10 +20,9 @@ zstd = { version = "0.13", optional = true } rust-lzma = { version = "0.6.0", optional = true } [features] -default = ["compression_zlib", "compression_bzip2", "compression_lzma", "compression_zstd"] -compression_zlib = ["dep:flate2", "compression"] -compression_bzip2 = ["dep:bzip2", "compression"] -compression_lzma = ["dep:rust-lzma", "compression"] -compression_zstd = ["dep:zstd", "compression"] -compression = [] +default = ["compression_lzma"] +compression_zlib = ["dep:flate2"] +compression_bzip2 = ["dep:bzip2"] +compression_lzma = ["dep:rust-lzma"] +compression_zstd = ["dep:zstd"] c_api = [] diff --git a/servicepoint2/src/command.rs b/servicepoint2/src/command.rs index 4a9f61f..d9601ae 100644 --- a/servicepoint2/src/command.rs +++ b/servicepoint2/src/command.rs @@ -104,9 +104,13 @@ impl From for Packet { CompressionCode::Uncompressed => { CommandCode::BitmapLinearWinUncompressed } + #[cfg(feature = "compression_zlib")] CompressionCode::Zlib => CommandCode::BitmapLinearWinZlib, + #[cfg(feature = "compression_bzip2")] CompressionCode::Bzip2 => CommandCode::BitmapLinearWinBzip2, + #[cfg(feature = "compression_lzma")] CompressionCode::Lzma => CommandCode::BitmapLinearWinLzma, + #[cfg(feature = "compression_zstd")] CompressionCode::Zstd => CommandCode::BitmapLinearWinZstd, }; @@ -263,15 +267,19 @@ impl TryFrom for Command { CompressionCode::Uncompressed, ) } + #[cfg(feature = "compression_zlib")] CommandCode::BitmapLinearWinZlib => { Self::packet_into_bitmap_win(packet, CompressionCode::Zlib) } + #[cfg(feature = "compression_bzip2")] CommandCode::BitmapLinearWinBzip2 => { Self::packet_into_bitmap_win(packet, CompressionCode::Bzip2) } + #[cfg(feature = "compression_lzma")] CommandCode::BitmapLinearWinLzma => { Self::packet_into_bitmap_win(packet, CompressionCode::Lzma) } + #[cfg(feature = "compression_zstd")] CommandCode::BitmapLinearWinZstd => { Self::packet_into_bitmap_win(packet, CompressionCode::Zstd) } @@ -541,8 +549,8 @@ mod tests { use crate::command::TryFromPacketError; use crate::command_code::CommandCode; use crate::{ - BitVec, ByteGrid, Command, CompressionCode, Header, Origin, Packet, - PixelGrid, + BitVec, ByteGrid, Command, CompressionCode, Grid, Header, Origin, + Packet, PixelGrid, }; fn round_trip(original: Command) { @@ -554,12 +562,16 @@ mod tests { assert_eq!(copy, original); } - fn all_compressions() -> [CompressionCode; 5] { - [ + fn all_compressions<'t>() -> &'t [CompressionCode] { + &[ CompressionCode::Uncompressed, + #[cfg(feature = "compression_lzma")] CompressionCode::Lzma, + #[cfg(feature = "compression_bzip2")] CompressionCode::Bzip2, + #[cfg(feature = "compression_zlib")] CompressionCode::Zlib, + #[cfg(feature = "compression_zstd")] CompressionCode::Zstd, ] } @@ -602,7 +614,7 @@ mod tests { #[test] fn round_trip_bitmap_linear() { - for compression in all_compressions() { + for compression in all_compressions().to_owned() { round_trip(Command::BitmapLinear(23, BitVec::new(40), compression)); round_trip(Command::BitmapLinearAnd( 23, @@ -704,7 +716,7 @@ mod tests { #[test] fn error_decompression_failed_win() { - for compression in all_compressions() { + for compression in all_compressions().to_owned() { let p: Packet = Command::BitmapLinearWin( Origin(16, 8), PixelGrid::new(8, 8), @@ -730,7 +742,7 @@ mod tests { #[test] fn error_decompression_failed_and() { - for compression in all_compressions() { + for compression in all_compressions().to_owned() { let p: Packet = Command::BitmapLinearAnd(0, BitVec::new(8), compression).into(); let Packet(header, mut payload) = p; diff --git a/servicepoint2/src/command_code.rs b/servicepoint2/src/command_code.rs index 73edc9d..3b4347c 100644 --- a/servicepoint2/src/command_code.rs +++ b/servicepoint2/src/command_code.rs @@ -15,9 +15,13 @@ pub(crate) enum CommandCode { BitmapLinearAnd = 0x0014, BitmapLinearOr = 0x0015, BitmapLinearXor = 0x0016, + #[cfg(feature = "compression_zlib")] BitmapLinearWinZlib = 0x0017, + #[cfg(feature = "compression_bzip2")] BitmapLinearWinBzip2 = 0x0018, + #[cfg(feature = "compression_lzma")] BitmapLinearWinLzma = 0x0019, + #[cfg(feature = "compression_zstd")] BitmapLinearWinZstd = 0x001A, } @@ -51,15 +55,19 @@ impl TryFrom for CommandCode { value if value == BitmapLinearAnd as u16 => Ok(BitmapLinearAnd), value if value == BitmapLinearOr as u16 => Ok(BitmapLinearOr), value if value == BitmapLinearXor as u16 => Ok(BitmapLinearXor), + #[cfg(feature = "compression_zstd")] value if value == BitmapLinearWinZstd as u16 => { Ok(BitmapLinearWinZstd) } + #[cfg(feature = "compression_lzma")] value if value == BitmapLinearWinLzma as u16 => { Ok(BitmapLinearWinLzma) } + #[cfg(feature = "compression_zlib")] value if value == BitmapLinearWinZlib as u16 => { Ok(BitmapLinearWinZlib) } + #[cfg(feature = "compression_bzip2")] value if value == BitmapLinearWinBzip2 as u16 => { Ok(BitmapLinearWinBzip2) } diff --git a/servicepoint2/src/compression.rs b/servicepoint2/src/compression.rs index 50af136..2e78073 100644 --- a/servicepoint2/src/compression.rs +++ b/servicepoint2/src/compression.rs @@ -1,4 +1,4 @@ -#[cfg(feature = "compression")] +#[allow(unused)] use std::io::{Read, Write}; #[cfg(feature = "compression_bzip2")]