@@ -6,21 +6,20 @@ macro_rules! buf_get_impl {
66 // try to convert directly from the bytes
77 // this Option<ret> trick is to avoid keeping a borrow on self
88 // when advance() is called (mut borrow) and to call bytes() only once
9- let ret = $this
10- . chunk( )
11- . get ( .. SIZE )
12- . map ( |src| unsafe { $typ :: $conv ( * ( src as * const _ as * const [ _ ; SIZE ] ) ) } ) ;
9+ # [ allow ( clippy :: ptr_as_ptr ) ]
10+ let ret = $this . chunk( ) . get ( .. SIZE ) . map ( |src| unsafe {
11+ $typ :: $conv ( * ( std :: ptr :: from_ref ( src ) as * const [ _ ; SIZE ] ) )
12+ } ) ;
1313
1414 if let Some ( ret) = ret {
1515 // if the direct conversion was possible, advance and return
1616 $this. advance( SIZE ) ;
1717 return ret;
18- } else {
19- // if not we copy the bytes in a temp buffer then convert
20- let mut buf = [ 0 ; SIZE ] ;
21- $this. copy_to_slice( & mut buf) ; // (do the advance)
22- return $typ:: $conv( buf) ;
2318 }
19+ // if not we copy the bytes in a temp buffer then convert
20+ let mut buf = [ 0 ; SIZE ] ;
21+ $this. copy_to_slice( & mut buf) ; // (do the advance)
22+ return $typ:: $conv( buf) ;
2423 } } ;
2524 ( le => $this: ident, $typ: tt, $len_to_read: expr) => { {
2625 debug_assert!( mem:: size_of:: <$typ>( ) >= $len_to_read) ;
@@ -804,7 +803,7 @@ impl<T: Buf + ?Sized> Buf for &mut T {
804803
805804 #[ inline]
806805 fn advance ( & mut self , cnt : usize ) {
807- ( * * self ) . advance ( cnt)
806+ ( * * self ) . advance ( cnt) ;
808807 }
809808}
810809
@@ -820,7 +819,7 @@ impl<T: Buf + ?Sized> Buf for Box<T> {
820819 }
821820
822821 fn advance ( & mut self , cnt : usize ) {
823- ( * * self ) . advance ( cnt)
822+ ( * * self ) . advance ( cnt) ;
824823 }
825824}
826825
@@ -896,6 +895,7 @@ impl<T: AsRef<[u8]>> Buf for std::io::Cursor<T> {
896895fn _assert_trait_object ( _b : & dyn Buf ) { }
897896
898897#[ cfg( test) ]
898+ #[ allow( clippy:: float_cmp) ]
899899mod tests {
900900 use super :: * ;
901901
@@ -950,56 +950,56 @@ mod tests {
950950 assert_eq ! ( 0x0809 , buf. get_i16_le( ) ) ;
951951
952952 let mut buf = & b"\x08 \x09 \xA0 \xA1 hello" [ ..] ;
953- assert_eq ! ( 0x0809A0A1 , buf. get_u32( ) ) ;
953+ assert_eq ! ( 0x0809_A0A1 , buf. get_u32( ) ) ;
954954
955955 let mut buf = & b"\xA1 \xA0 \x09 \x08 hello" [ ..] ;
956- assert_eq ! ( 0x0809A0A1 , buf. get_u32_le( ) ) ;
956+ assert_eq ! ( 0x0809_A0A1 , buf. get_u32_le( ) ) ;
957957
958958 let mut buf = & b"\x08 \x09 \xA0 \xA1 hello" [ ..] ;
959- assert_eq ! ( 0x0809A0A1 , buf. get_i32( ) ) ;
959+ assert_eq ! ( 0x0809_A0A1 , buf. get_i32( ) ) ;
960960
961961 let mut buf = & b"\xA1 \xA0 \x09 \x08 hello" [ ..] ;
962- assert_eq ! ( 0x0809A0A1 , buf. get_i32_le( ) ) ;
962+ assert_eq ! ( 0x0809_A0A1 , buf. get_i32_le( ) ) ;
963963
964964 let mut buf = & b"\x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 hello" [ ..] ;
965- assert_eq ! ( 0x0102030405060708 , buf. get_u64( ) ) ;
965+ assert_eq ! ( 0x0102_0304_0506_0708 , buf. get_u64( ) ) ;
966966
967967 let mut buf = & b"\x08 \x07 \x06 \x05 \x04 \x03 \x02 \x01 hello" [ ..] ;
968- assert_eq ! ( 0x0102030405060708 , buf. get_u64_le( ) ) ;
968+ assert_eq ! ( 0x0102_0304_0506_0708 , buf. get_u64_le( ) ) ;
969969
970970 let mut buf = & b"\x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 hello" [ ..] ;
971- assert_eq ! ( 0x0102030405060708 , buf. get_i64( ) ) ;
971+ assert_eq ! ( 0x0102_0304_0506_0708 , buf. get_i64( ) ) ;
972972
973973 let mut buf = & b"\x08 \x07 \x06 \x05 \x04 \x03 \x02 \x01 hello" [ ..] ;
974- assert_eq ! ( 0x0102030405060708 , buf. get_i64_le( ) ) ;
974+ assert_eq ! ( 0x0102_0304_0506_0708 , buf. get_i64_le( ) ) ;
975975
976976 let mut buf =
977977 & b"\x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 \x09 \x10 \x11 \x12 \x13 \x14 \x15 \x16 hello" [ ..] ;
978- assert_eq ! ( 0x01020304050607080910111213141516 , buf. get_u128( ) ) ;
978+ assert_eq ! ( 0x0102_0304_0506_0708_0910_1112_1314_1516 , buf. get_u128( ) ) ;
979979
980980 let mut buf =
981981 & b"\x16 \x15 \x14 \x13 \x12 \x11 \x10 \x09 \x08 \x07 \x06 \x05 \x04 \x03 \x02 \x01 hello" [ ..] ;
982- assert_eq ! ( 0x01020304050607080910111213141516 , buf. get_u128_le( ) ) ;
982+ assert_eq ! ( 0x0102_0304_0506_0708_0910_1112_1314_1516 , buf. get_u128_le( ) ) ;
983983
984984 let mut buf =
985985 & b"\x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 \x09 \x10 \x11 \x12 \x13 \x14 \x15 \x16 hello" [ ..] ;
986- assert_eq ! ( 0x01020304050607080910111213141516 , buf. get_i128( ) ) ;
986+ assert_eq ! ( 0x0102_0304_0506_0708_0910_1112_1314_1516 , buf. get_i128( ) ) ;
987987
988988 let mut buf =
989989 & b"\x16 \x15 \x14 \x13 \x12 \x11 \x10 \x09 \x08 \x07 \x06 \x05 \x04 \x03 \x02 \x01 hello" [ ..] ;
990- assert_eq ! ( 0x01020304050607080910111213141516 , buf. get_i128_le( ) ) ;
990+ assert_eq ! ( 0x0102_0304_0506_0708_0910_1112_1314_1516 , buf. get_i128_le( ) ) ;
991991
992992 let mut buf = & b"\x01 \x02 \x03 hello" [ ..] ;
993- assert_eq ! ( 0x010203 , buf. get_uint( 3 ) ) ;
993+ assert_eq ! ( 0x01_0203 , buf. get_uint( 3 ) ) ;
994994
995995 let mut buf = & b"\x03 \x02 \x01 hello" [ ..] ;
996- assert_eq ! ( 0x010203 , buf. get_uint_le( 3 ) ) ;
996+ assert_eq ! ( 0x01_0203 , buf. get_uint_le( 3 ) ) ;
997997
998998 let mut buf = & b"\x01 \x02 \x03 hello" [ ..] ;
999- assert_eq ! ( 0x010203 , buf. get_int( 3 ) ) ;
999+ assert_eq ! ( 0x01_0203 , buf. get_int( 3 ) ) ;
10001000
10011001 let mut buf = & b"\x03 \x02 \x01 hello" [ ..] ;
1002- assert_eq ! ( 0x010203 , buf. get_int_le( 3 ) ) ;
1002+ assert_eq ! ( 0x01_0203 , buf. get_int_le( 3 ) ) ;
10031003
10041004 let mut buf = & b"\x3F \x99 \x99 \x9A hello" [ ..] ;
10051005 assert_eq ! ( 1.2f32 , buf. get_f32( ) ) ;
0 commit comments