Fix a hard error in clippy

This commit is contained in:
Josh Holmer 2021-11-15 11:41:40 -05:00
parent 2d16819cbf
commit bc0d673af0

View file

@ -5,17 +5,7 @@ use libdeflater::{CompressionError, CompressionLvl, Compressor};
pub fn deflate(data: &[u8], max_size: &AtomicMin) -> PngResult<Vec<u8>> {
let mut compressor = Compressor::new(CompressionLvl::best());
let capacity = max_size.get().unwrap_or(data.len() / 2);
let mut dest = Vec::with_capacity(capacity);
unsafe {
// This is ok because the Vec contains Copy-able data (u8)
// and because libdeflater wrapper doesn't try to read
// the bytes from the target.
//
// That said, it should be able to accept MaybeUninit instead,
// so I raised an upstream issue that should make this safer:
// https://github.com/adamkewley/libdeflater/issues/1
dest.set_len(capacity);
}
let mut dest = vec![0; capacity];
let len = compressor
.zlib_compress(data, &mut dest)
.map_err(|err| match err {