Skip to content

Commit

Permalink
fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
ihciah committed Oct 31, 2024
1 parent 2fc1e98 commit fe0bc98
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
28 changes: 9 additions & 19 deletions monoio/src/fs/file/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 { slice::from_raw_parts(raw_bufs, len, 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(),
Expand Down Expand Up @@ -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.
Expand All @@ -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 { slice::from_raw_parts(raw_bufs, len, len) };
let mut total_bytes_write = 0;

// Iterate through each WSABUF structure and write data from it
Expand Down Expand Up @@ -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 { 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
Expand Down Expand Up @@ -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.
Expand All @@ -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 { slice::from_raw_parts(raw_bufs as *mut WSABUF, len, len) };

let mut total_bytes_write = 0;

Expand Down
2 changes: 1 addition & 1 deletion monoio/src/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit fe0bc98

Please sign in to comment.