pub(crate) fn compress(&self, mut dest: Vec<u8>, src: &[u8]) -> Result<Vec<u8>, ()> {
        match self {
            Compress::None => Err(()),
            Compress::General { level, .. } => {
                let dest_len = dest.len();
                let max_len = zstd_safe::compress_bound(src.len());
                dest.reserve(max_len);
                unsafe {
                    dest.set_len(dest_len + max_len);
                    match zstd_safe::compress(&mut dest[dest_len..], src, *level as i32) {
                        Ok(len) if len < src.len() => {
                            dest.truncate(dest_len + len);
                            Ok(dest)
                        }
                        _ => Err(()),
                    }
                }
            }
            Compress::Dict(dict) => {
                let dest_len = dest.len();
                let max_len = zstd_safe::compress_bound(src.len());
                dest.reserve(max_len);
                unsafe {
                    dest.set_len(dest_len + max_len);
                    match &dict.0 {
                        DictionaryPrivate::Unknown { level, .. } => {
                            match zstd_safe::compress(&mut dest[dest_len..], src, *level as i32) {
                                Ok(len) if len < src.len() => {
                                    dest.truncate(dest_len + len);
                                    Ok(dest)
                                }
                                _ => Err(()),
                            }
                        }
                        DictionaryPrivate::Zstd { cdict, .. } => {
                            let mut ctx = zstd_safe::create_cctx();
                            match ctx.compress_using_cdict(&mut dest[dest_len..], src, cdict) {
                                Ok(len) if len < src.len() => {
                                    dest.truncate(dest_len + len);
                                    Ok(dest)
                                }
                                _ => Err(()),
                            }
                        }
                    }
                }
            }
        }
    }
/// Attempt to compress the data. Failure occurs if this shouldn't compress, compression fails,
/// or the result is longer than the original. On failure, the buffer is discarded.
Attempt to compress the data. Failure occurs if this shouldn't compress, compression fails,
or the result is longer than the original. On failure, the buffer is discarded.
Attempt to compress the data . Failure occurs if this shouldn ' t compress compression fails or the result is longer than the original . On failure the buffer is discarded .
pub(crate) fn compress(&self, mut dest: Vec<u8>, src: &[u8]) -> Result<Vec<u8>, ()> {
        match self {
            Compress::None => Err(()),
            Compress::General { level, .. } => {
                let dest_len = dest.len();
                let max_len = zstd_safe::compress_bound(src.len());
                dest.reserve(max_len);
                unsafe {
                    dest.set_len(dest_len + max_len);
                    match zstd_safe::compress(&mut dest[dest_len..], src, *level as i32) {
                        Ok(len) if len < src.len() => {
                            dest.truncate(dest_len + len);
                            Ok(dest)
                        }
                        _ => Err(()),
                    }
                }
            }
            Compress::Dict(dict) => {
                let dest_len = dest.len();
                let max_len = zstd_safe::compress_bound(src.len());
                dest.reserve(max_len);
                unsafe {
                    dest.set_len(dest_len + max_len);
                    match &dict.0 {
                        DictionaryPrivate::Unknown { level, .. } => {
                            match zstd_safe::compress(&mut dest[dest_len..], src, *level as i32) {
                                Ok(len) if len < src.len() => {
                                    dest.truncate(dest_len + len);
                                    Ok(dest)
                                }
                                _ => Err(()),
                            }
                        }
                        DictionaryPrivate::Zstd { cdict, .. } => {
                            let mut ctx = zstd_safe::create_cctx();
                            match ctx.compress_using_cdict(&mut dest[dest_len..], src, cdict) {
                                Ok(len) if len < src.len() => {
                                    dest.truncate(dest_len + len);
                                    Ok(dest)
                                }
                                _ => Err(()),
                            }
                        }
                    }
                }
            }
        }
    }
pub ( crate ) fn compress ( & self , mut dest : Vec < u8 > , src : & [ u8 ] ) -> Result < Vec < u8 > , ( ) > { match self { Compress :: None => Err ( ( ) ) , Compress :: General { level , .. } => { let dest_len = dest . len ( ) ; let max_len = zstd_safe :: compress_bound ( src . len ( ) ) ; dest . reserve ( max_len ) ; unsafe { dest . set_len ( dest_len + max_len ) ; match zstd_safe :: compress ( & mut dest [ dest_len .. ] , src , * level as i32 ) { Ok ( len ) if len < src . len ( ) => { dest . truncate ( dest_len + len ) ; Ok ( dest ) } _ => Err ( ( ) ) , } } } Compress :: Dict ( dict ) => { let dest_len = dest . len ( ) ; let max_len = zstd_safe :: compress_bound ( src . len ( ) ) ; dest . reserve ( max_len ) ; unsafe { dest . set_len ( dest_len + max_len ) ; match & dict . 0 { DictionaryPrivate :: Unknown { level , .. } => { match zstd_safe :: compress ( & mut dest [ dest_len .. ] , src , * level as i32 ) { Ok ( len ) if len < src . len ( ) => { dest . truncate ( dest_len + len ) ; Ok ( dest ) } _ => Err ( ( ) ) , } } DictionaryPrivate :: Zstd { cdict , .. } => { let mut ctx = zstd_safe :: create_cctx ( ) ; match ctx . compress_using_cdict ( & mut dest [ dest_len .. ] , src , cdict ) { Ok ( len ) if len < src . len ( ) => { dest . truncate ( dest_len + len ) ; Ok ( dest ) } _ => Err ( ( ) ) , } } } } } } }
Attempt to compress the data.
Attempt to compress the data .
&self
dest
Vec<u8>
src
&[u8]
&self
dest
Vec<u8>
src
&[u8]