From 40ccb8674e38c081bd251c35a907106a14c91c9a Mon Sep 17 00:00:00 2001 From: Skgland Date: Sat, 28 Mar 2026 13:22:03 +0100 Subject: [PATCH] replace winapi with windows-sys --- Cargo.toml | 16 +++++++++------- src/lib.rs | 17 +++++++++-------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c5b9dc6..32ff084 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,15 @@ default = [] libudev = ["serialport/libudev"] serde = ["serialport/serde"] +[dependencies] +windows-sys = { version = ">=0.59.0,<0.62", features = [ + "Win32_Devices_Communication", + "Win32_Storage_FileSystem", + "Win32_Foundation", + # required for CreateFileW to be available in 0.59 & 0.60 + "Win32_Security", +] } + [dependencies.mio] version = "1" features = ["os-poll", "os-ext"] @@ -34,13 +43,6 @@ version = "0.4" [target.'cfg(unix)'.dependencies] nix = { version = "0.29", features = ["term"] } -[target.'cfg(windows)'.dependencies] -winapi = { version = "0.3", features = [ - "commapi", - "handleapi", - "winbase", - "std", -] } [dev-dependencies.env_logger] version = "0.11" diff --git a/src/lib.rs b/src/lib.rs index f8379ce..0316df5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -60,12 +60,13 @@ mod os_prelude { pub use std::os::windows::io::{FromRawHandle, RawHandle}; pub use std::path::Path; pub use std::ptr; - pub use winapi::um::commapi::SetCommTimeouts; - pub use winapi::um::fileapi::*; - pub use winapi::um::handleapi::INVALID_HANDLE_VALUE; - pub use winapi::um::winbase::{COMMTIMEOUTS, FILE_FLAG_OVERLAPPED}; - pub use winapi::um::winnt::{ - FILE_ATTRIBUTE_NORMAL, GENERIC_READ, GENERIC_WRITE, HANDLE, + + pub use windows_sys::Win32::Devices::Communication::{SetCommTimeouts, COMMTIMEOUTS}; + pub use windows_sys::Win32::Foundation::{ + GENERIC_READ, GENERIC_WRITE, HANDLE, INVALID_HANDLE_VALUE, + }; + pub use windows_sys::Win32::Storage::FileSystem::{ + CreateFileW, FILE_ATTRIBUTE_NORMAL, FILE_FLAG_OVERLAPPED, OPEN_EXISTING, }; } use os_prelude::*; @@ -792,7 +793,7 @@ mod sys { /// Overrides timeout value set by serialport-rs so that the read end will /// never wake up with 0-byte payload. pub(crate) fn override_comm_timeouts(handle: RawHandle) -> StdIoResult<()> { - let mut timeouts = COMMTIMEOUTS { + let timeouts = COMMTIMEOUTS { // wait at most 1ms between two bytes (0 means no timeout) ReadIntervalTimeout: 1, // disable "total" timeout to wait at least 1 byte forever @@ -803,7 +804,7 @@ mod sys { WriteTotalTimeoutConstant: 0, }; - let r = unsafe { SetCommTimeouts(handle, &mut timeouts) }; + let r = unsafe { SetCommTimeouts(handle, &timeouts) }; if r == 0 { return Err(io::Error::last_os_error()); }