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

Make handle fields const #1468

Merged
merged 6 commits into from Jan 27, 2022
Merged

Make handle fields const #1468

merged 6 commits into from Jan 27, 2022

Conversation

kennykerr
Copy link
Collaborator

@kennykerr kennykerr commented Jan 27, 2022

Handle fields don't need to be mutable and it's easier to work with handles when they're *const rather than *mut. This mainly affects string handle types like PWSTR/PSTR/BSTR and particularly helps with the usage of windows-sys crate. For example, the readme sample can now be written as follows:

fn main() {
    unsafe {
        let event = CreateEventW(std::ptr::null(), 1, 0, std::ptr::null());
        SetEvent(event);
        WaitForSingleObject(event, 0);
        CloseHandle(event);
        MessageBoxA(0, b"Text\0".as_ptr(), b"Caption\0".as_ptr(), MB_OK);
    }
}

Previously it needed a lot more mutability:

fn main() {
    unsafe {
        let event = CreateEventW(std::ptr::null_mut(), 1, 0, std::ptr::null_mut());
        SetEvent(event);
        WaitForSingleObject(event, 0);
        CloseHandle(event);
        MessageBoxA(0, b"Text\0".as_ptr() as _, b"Caption\0".as_ptr() as _, MB_OK);
    }
}

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

1 participant