@@ -19,18 +19,14 @@ use std::{
1919 io:: Read ,
2020 mem,
2121 num:: NonZeroUsize ,
22+ ptr:: slice_from_raw_parts_mut,
2223} ;
2324
2425use self :: error:: PacketCodecError ;
2526use crate :: constants:: { DEFAULT_MAX_ALLOWED_PACKET , MAX_PAYLOAD_LEN , MIN_COMPRESS_LENGTH } ;
2627
2728pub mod error;
2829
29- /// Helper that transmutes `&mut [MaybeUninit<u8>]` to `&mut [u8]`.
30- pub ( crate ) unsafe fn transmute_buf ( buf : & mut [ mem:: MaybeUninit < u8 > ] ) -> & mut [ u8 ] {
31- & mut * ( buf as * mut [ mem:: MaybeUninit < u8 > ] as * mut [ u8 ] )
32- }
33-
3430/// Will split given `packet` to MySql packet chunks and write into `dst`.
3531///
3632/// Chunk ids will start with given `seq_id`.
@@ -80,7 +76,10 @@ pub fn compress(
8076 loop {
8177 dst. reserve ( max ( chunk. len ( ) . saturating_sub ( read) , 1 ) ) ;
8278 let dst_buf = & mut dst. bytes_mut ( ) [ 7 + read..] ;
83- match encoder. read ( transmute_buf ( dst_buf) ) ? {
79+ match encoder. read ( & mut * slice_from_raw_parts_mut (
80+ dst_buf. as_mut_ptr ( ) ,
81+ dst_buf. len ( ) ,
82+ ) ) ? {
8483 0 => break ,
8584 count => read += count,
8685 }
@@ -316,8 +315,10 @@ impl CompDecoder {
316315 dst. reserve ( plain_len. get ( ) ) ;
317316 unsafe {
318317 let mut decoder = ZlibDecoder :: new ( & src[ ..needed. get ( ) ] ) ;
319- decoder. read_exact ( transmute_buf (
320- & mut dst. bytes_mut ( ) [ ..plain_len. get ( ) ] ,
318+ let dst_buf = & mut dst. bytes_mut ( ) [ ..plain_len. get ( ) ] ;
319+ decoder. read_exact ( & mut * slice_from_raw_parts_mut (
320+ dst_buf. as_mut_ptr ( ) ,
321+ dst_buf. len ( ) ,
321322 ) ) ?;
322323 dst. advance_mut ( plain_len. get ( ) ) ;
323324 }
0 commit comments