message: remove RawSlice by referencing the boxed slice directly
diff: @@ -195,12 +195,6 @@ pub enum RTL8139Error {
  Unknown,
  }
  -#[derive(Copy, Clone, Debug)]
  -struct RawSlice<T> {
  - pub ptr: *mut T,
  - pub len: usize,
  -}
  -
  /// RealTek RTL8139 network driver struct.
  ///
  /// Struct allows to control device queues as also
  @@ -215,7 +209,7 @@ pub struct RTL8139Driver {
  rxbuffer: Box<[u8]>,
  rxpos: usize,
  txbuffer: Box<[u8]>,
  - box_map: BTreeMap<usize, RawSlice<u8>>,
  + box_map: BTreeMap<usize, Box<[u8]>>,
  }
  impl NetworkInterface for RTL8139Driver {
  @@ -297,22 +291,16 @@ impl NetworkInterface for RTL8139Driver {
  msg[limit..].copy_from_slice(&self.rxbuffer[0..length as usize - limit]);
  // buffer address to release box in `rx_buffer_consumed`
  - let raw_msg = Box::leak(msg);
  - self.box_map.insert(
  - self.rxpos,
  - RawSlice {
  - ptr: raw_msg.as_mut_ptr(),
  - len: length as usize,
  - },
  - );
  + let msg_ptr = msg.as_ptr() as *const u8;
  + self.box_map.insert(self.rxpos, msg);
  - raw_msg
  + msg_ptr
  } else {
  - &self.rxbuffer[pos..][..length.into()]
  + self.rxbuffer[pos..].as_ptr() as *const u8
  };
  // SAFETY: This is a blatant lie and very unsound.
  // The API must be fixed or the buffer may never touched again.
  - let buf = unsafe { mem::transmute(buf) };
  + let buf = unsafe { slice::from_raw_parts(buf, length.into()) };
  Ok((buf, self.rxpos))
  } else {
  @@ -334,14 +322,8 @@ impl NetworkInterface for RTL8139Driver {
  warn!("Invalid handle {} != {}", self.rxpos, handle)
  }
  - match self.box_map.remove_entry(&self.rxpos) {
  - Some((_, raw)) => {
  - // release temporay created boxed slice
  - let _buffer: Box<[u8]> =
  - unsafe { Box::from_raw(slice::from_raw_parts_mut(raw.ptr, raw.len)) };
  - }
  - None => {}
  - }
  + // remove boxed packet
  + let _ = self.box_map.remove_entry(&self.rxpos);
  let length = self.rx_peek_u16();
  self.advance_rxpos(usize::from(length) + mem::size_of::<u16>());
  