From 221708e94adae948615c684b7c67bc8b22e75d57 Mon Sep 17 00:00:00 2001 From: ihciah Date: Thu, 31 Oct 2024 08:12:49 +0000 Subject: [PATCH] fix clippy --- monoio/src/fs/file/windows.rs | 28 +++++++++------------------- monoio/src/fs/mod.rs | 4 ++-- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/monoio/src/fs/file/windows.rs b/monoio/src/fs/file/windows.rs index 59e33ae7..696c9b30 100644 --- a/monoio/src/fs/file/windows.rs +++ b/monoio/src/fs/file/windows.rs @@ -12,7 +12,7 @@ use windows_sys::Win32::Networking::WinSock::WSABUF; use super::File; use crate::{ buf::{IoBuf, IoBufMut, IoVecBuf, IoVecBufMut}, - driver::{op::Op, shared_fd::SharedFd}, + driver::shared_fd::SharedFd, }; impl AsRawHandle for File { @@ -45,13 +45,12 @@ mod blocking { let raw_bufs = buf_vec.write_wsabuf_ptr(); let len = buf_vec.write_wsabuf_len(); - // Safely wrap the raw pointers into a Vec, but prevent automatic cleanup with ManuallyDrop - let wasbufs = ManuallyDrop::new(unsafe { Vec::from_raw_parts(raw_bufs, len, len) }); + let wsabufs = unsafe { std::slice::from_raw_parts(raw_bufs, len) }; let mut total_bytes_read = 0; // Iterate through each WSABUF structure and read data into it - for wsabuf in wasbufs.iter() { + for wsabuf in wsabufs.iter() { // Safely create a Vec from the WSABUF pointer, then pass it to the read function let (res, _) = read( fd.clone(), @@ -83,7 +82,7 @@ mod blocking { } /// The `writev` implement on windows - /// + /// /// Due to windows does not have syscall like `writev`, so we need to simulate it by ourself. /// /// This function is just to write each buffer into file by calling the `write` function. @@ -95,8 +94,7 @@ mod blocking { let raw_bufs = buf_vec.read_wsabuf_ptr() as *mut WSABUF; let len = buf_vec.read_wsabuf_len(); - // Safely wrap the raw pointers into a Vec, but prevent automatic cleanup with ManuallyDrop - let wsabufs = ManuallyDrop::new(unsafe { Vec::from_raw_parts(raw_bufs, len, len) }); + let wsabufs = unsafe { std::slice::from_raw_parts(raw_bufs, len) }; let mut total_bytes_write = 0; // Iterate through each WSABUF structure and write data from it @@ -162,16 +160,12 @@ mod asyncified { let fd = fd.as_raw_handle() as _; let res = asyncify(move || { - // Safely wrap the raw pointers into a Vec, but prevent automatic cleanup with - // ManuallyDrop - let wasbufs = ManuallyDrop::new(unsafe { - Vec::from_raw_parts(raw_bufs as *mut WSABUF, len, len) - }); + let wsabufs = unsafe { std::slice::from_raw_parts(raw_bufs as *mut WSABUF, len) }; let mut total_bytes_read = 0; // Iterate through each WSABUF structure and read data into it - for wsabuf in wasbufs.iter() { + for wsabuf in wsabufs.iter() { let res = read::read(fd, wsabuf.buf, wsabuf.len as usize); // Handle the result of the read operation @@ -203,7 +197,7 @@ mod asyncified { } /// The `writev` implement on windows - /// + /// /// Due to windows does not have syscall like `writev`, so we need to simulate it by ourself. /// /// This function is just to write each buffer into file by calling the `write` function. @@ -218,11 +212,7 @@ mod asyncified { let fd = fd.as_raw_handle() as _; let res = asyncify(move || { - // Safely wrap the raw pointers into a Vec, but prevent automatic cleanup with - // ManuallyDrop - let wsabufs = ManuallyDrop::new(unsafe { - Vec::from_raw_parts(raw_bufs as *mut WSABUF, len, len) - }); + let wsabufs = unsafe { std::slice::from_raw_parts(raw_bufs as *mut WSABUF, len) }; let mut total_bytes_write = 0; diff --git a/monoio/src/fs/mod.rs b/monoio/src/fs/mod.rs index 695a1b83..c752595b 100644 --- a/monoio/src/fs/mod.rs +++ b/monoio/src/fs/mod.rs @@ -36,7 +36,7 @@ pub use file_type::FileType; #[cfg(unix)] mod permissions; #[cfg(windows)] -use std::os::windows::io::{AsRawHandle, FromRawHandle, IntoRawHandle}; +use std::os::windows::io::{AsRawHandle, FromRawHandle}; #[cfg(unix)] pub use permissions::Permissions; @@ -92,7 +92,7 @@ where macro_rules! uring_op { ($fn_name:ident<$trait_name:ident>($op_name: ident, $buf_name:ident $(, $pos:ident: $pos_type:ty)?)) => { pub(crate) async fn $fn_name(fd: SharedFd, $buf_name: T, $($pos: $pos_type)?) -> $crate::BufResult { - let op = Op::$op_name(fd, $buf_name, $($pos)?).unwrap(); + let op = $crate::driver::op::Op::$op_name(fd, $buf_name, $($pos)?).unwrap(); op.result().await } };