Skip to content

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

Merged
0xpr03 merged 1 commit intonotify-rs:mainfrom
GamePad64:windows-rs
Dec 5, 2022
Merged

Use official windows-sys crate for WinAPI instead of deprecated winapi crate#457
0xpr03 merged 1 commit intonotify-rs:mainfrom
GamePad64:windows-rs

Conversation

@GamePad64
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Copy link
Copy Markdown

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
Copy Markdown
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!

@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.

3 participants