Skip to content

Commit

Permalink
feat: replace fns with From impl
Browse files Browse the repository at this point in the history
  • Loading branch information
CosminPerRam committed Feb 13, 2025
1 parent 4fd338c commit a6cac49
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions src/ffi/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ impl fmt::Debug for Inflate {
}
}

fn flush_decompress_into_mzflush(flush: FlushDecompress) -> MZFlush {
match flush {
FlushDecompress::None => MZFlush::None,
FlushDecompress::Sync => MZFlush::Sync,
FlushDecompress::Finish => MZFlush::Finish,
impl From<FlushDecompress> for MZFlush {
fn from(value: FlushDecompress) -> Self {
match value {
FlushDecompress::None => Self::None,
FlushDecompress::Sync => Self::Sync,
FlushDecompress::Finish => Self::Finish,
}
}
}

Expand All @@ -75,8 +77,8 @@ impl InflateBackend for Inflate {
output: &mut [u8],
flush: FlushDecompress,
) -> Result<Status, DecompressError> {
let flush = flush_decompress_into_mzflush(flush);
let res = inflate::stream::inflate(&mut self.inner, input, output, flush);
let mz_flush = flush.into();
let res = inflate::stream::inflate(&mut self.inner, input, output, mz_flush);
self.total_in += res.bytes_consumed as u64;
self.total_out += res.bytes_written as u64;

Expand Down Expand Up @@ -130,12 +132,14 @@ impl fmt::Debug for Deflate {
}
}

fn flush_compress_into_mzflush(flush: FlushCompress) -> MZFlush {
match flush {
FlushCompress::None => MZFlush::None,
FlushCompress::Sync | FlushCompress::Partial => MZFlush::Sync,
FlushCompress::Full => MZFlush::Full,
FlushCompress::Finish => MZFlush::Finish,
impl From<FlushCompress> for MZFlush {
fn from(value: FlushCompress) -> Self {
match value {
FlushCompress::None => Self::None,
FlushCompress::Sync | FlushCompress::Partial => Self::Sync,
FlushCompress::Full => Self::Full,
FlushCompress::Finish => Self::Finish,
}
}
}

Expand All @@ -161,8 +165,8 @@ impl DeflateBackend for Deflate {
output: &mut [u8],
flush: FlushCompress,
) -> Result<Status, CompressError> {
let flush = flush_compress_into_mzflush(flush);
let res = deflate::stream::deflate(&mut self.inner, input, output, flush);
let mz_flush = flush.into();
let res = deflate::stream::deflate(&mut self.inner, input, output, mz_flush);
self.total_in += res.bytes_consumed as u64;
self.total_out += res.bytes_written as u64;

Expand Down

0 comments on commit a6cac49

Please # to comment.