From 6d54680fedfcfc8c835f90348dd24825b2535aa0 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 | 30 +++++++++++------------------- monoio/src/fs/mod.rs | 4 ++-- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/monoio/src/fs/file/windows.rs b/monoio/src/fs/file/windows.rs index 59e33ae7..953bb01f 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,21 +160,18 @@ 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 match res { Ok(bytes_read) => { + let bytes_read = bytes_read.into_inner(); total_bytes_read += bytes_read; // If fewer bytes were read than requested, stop further reads if bytes_read < wsabuf.len { @@ -203,7 +198,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 +213,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; @@ -231,6 +222,7 @@ mod asyncified { match res { Ok(bytes_write) => { + let bytes_write = bytes_write.into_inner(); total_bytes_write += bytes_write; if bytes_write < wsabuf.len { break; 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 } };