Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use official windows-sys crate for WinAPI instead of deprecated winapi crate #457

Merged
merged 1 commit into from
Dec 5, 2022

Conversation

GamePad64
Copy link
Contributor

winapi crate is kinda deprecated. windows and windows-sys can be used instead. They are maintained directly by Microsoft and are actively developed.
windows-sys is a trimmed down version of windows. It offers better compilation time, and it is released once per 6 months.

I removed winapi dependency and replaced in with windows-sys.

@GamePad64
Copy link
Contributor Author

Btw, windows-sys MSRV is 1.49

CloseHandle, ERROR_OPERATION_ABORTED, HANDLE, INVALID_HANDLE_VALUE, WAIT_OBJECT_0,
};
use windows_sys::Win32::Storage::FileSystem::{
CreateFileW, ReadDirectoryChangesW, FILE_ACTION_ADDED, FILE_ACTION_MODIFIED,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to just do ::* for this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

windows_sys::Win32::Storage::FileSystem is pretty big, so ::* may lead to great scope pollution…
I am thinking about use windows_sys::Win32::Storage::FileSystem as fileapi, so it will have a short name, like in winapi.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sometimes use a custom prelude module for that

mod win  {
    pub use windows_sys::Win32::Foundation::*;
    pub use windows_sys::Win32::Storage::*;
    pub use windows_sys::Win32::Threading::*;
    pub use windows_sys::Win32::WindowsProgramming::*;
    pub use windows_sys::Win32::IO::*;
}

// ...
handle = win::CreateFileW(
    encoded_path.as_ptr(),
    win::FILE_LIST_DIRECTORY,
    win::FILE_SHARE_READ | win::FILE_SHARE_DELETE | win::FILE_SHARE_WRITE,
    ptr::null_mut(),
    win::OPEN_EXISTING,
    win::FILE_FLAG_BACKUP_SEMANTICS | win::FILE_FLAG_OVERLAPPED,
    0,
);

Copy link
Member

@0xpr03 0xpr03 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

notify/src/windows.rs Show resolved Hide resolved
@0xpr03 0xpr03 merged commit b23efcb into notify-rs:main Dec 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants