Skip to content
New issue

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

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

Already on GitHub? # to your account

Make Windows and Web handles !Send and !Sync #154

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,9 @@ mod tests {
assert_not_impl_any!(WaylandWindowHandle: Send, Sync);
assert_impl_all!(DrmWindowHandle: Send, Sync);
assert_not_impl_any!(GbmWindowHandle: Send, Sync);
assert_impl_all!(Win32WindowHandle: Send, Sync);
assert_not_impl_any!(Win32WindowHandle: Send, Sync);
assert_not_impl_any!(WinRtWindowHandle: Send, Sync);
assert_impl_all!(WebWindowHandle: Send, Sync);
assert_not_impl_any!(WebWindowHandle: Send, Sync);
assert_not_impl_any!(WebCanvasWindowHandle: Send, Sync);
assert_not_impl_any!(WebOffscreenCanvasWindowHandle: Send, Sync);
assert_not_impl_any!(AndroidNdkWindowHandle: Send, Sync);
Expand Down
7 changes: 6 additions & 1 deletion src/web.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use core::ffi::c_void;
use core::marker::PhantomData;
use core::ptr::NonNull;

use super::DisplayHandle;
Expand Down Expand Up @@ -55,6 +56,7 @@ pub struct WebWindowHandle {
///
/// [data attributes]: https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/data-*
pub id: u32,
_marker: PhantomData<*const ()>,
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure what to think of this, the ID here is not a pointer, but it might be misleading for consumers who think that they are on the main thread if they got this variant.

Is there any previous discussion on this?

Copy link
Member

Choose a reason for hiding this comment

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

I was also wondering if there are any plans to remove this type completely, now that we have the WebCanvasWindowHandle and WebOffscreenCanvasWindowHandle types.

Copy link
Member Author

Choose a reason for hiding this comment

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

plans to remove this type completely

Moved to #157.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure what to think of this, the ID here is not a pointer, but it might be misleading for consumers who think that they are on the main thread if they got this variant.

Well, that's the same as what I've documented on e.g. AppKitWindowHandle, but I'm beginning to see that that may not be the best approach (hence why this PR isn't merged yet).

Copy link
Member

Choose a reason for hiding this comment

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

After some more thinking I'm now in favor of making this !Send.

}

impl WebWindowHandle {
Expand All @@ -70,7 +72,10 @@ impl WebWindowHandle {
/// let handle = WebWindowHandle::new(id);
/// ```
pub fn new(id: u32) -> Self {
Self { id }
Self {
id,
_marker: PhantomData,
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/windows.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use core::ffi::c_void;
use core::marker::PhantomData;
use core::num::NonZeroIsize;
use core::ptr::NonNull;

Expand Down Expand Up @@ -54,6 +55,7 @@ pub struct Win32WindowHandle {
pub hwnd: NonZeroIsize,
/// The `GWLP_HINSTANCE` associated with this type's `HWND`.
pub hinstance: Option<NonZeroIsize>,
_marker: PhantomData<*const ()>,
}

impl Win32WindowHandle {
Expand All @@ -80,6 +82,7 @@ impl Win32WindowHandle {
Self {
hwnd,
hinstance: None,
_marker: PhantomData,
}
}
}
Expand Down
Loading