From 15ca02f491d4b01f0aab840f71e0ccbb008f6238 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20du=20Garreau?= Date: Mon, 13 Jan 2020 23:54:32 +0100 Subject: [PATCH 1/2] Remove _do_not_use tags to use #[non_exhaustive] macro --- CHANGELOG.md | 1 + src/android.rs | 6 +----- src/ios.rs | 6 +----- src/lib.rs | 10 +--------- src/macos.rs | 6 +----- src/unix.rs | 18 +++--------------- src/web.rs | 10 ++-------- src/windows.rs | 6 +----- 8 files changed, 11 insertions(+), 52 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77200ef..a31f928 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Unreleased * **Breaking:** Change type for pointers, which may be null, to `Option>`. +* **Breaking** Remove `_do_not_use` tags to use `#[non_exhaustive]` macro # 0.3.3 (2019-12-1) diff --git a/src/android.rs b/src/android.rs index a25b618..2cf849a 100644 --- a/src/android.rs +++ b/src/android.rs @@ -11,21 +11,17 @@ use core::ptr::NonNull; /// ..AndroidHandle::empty() /// }; /// ``` +#[non_exhaustive] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct AndroidHandle { /// A pointer to an ANativeWindow. pub a_native_window: Option>, - #[doc(hidden)] - #[deprecated = "This field is used to ensure that this struct is non-exhaustive, so that it may be extended in the future. Do not refer to this field."] - pub _non_exhaustive_do_not_use: crate::seal::Seal, } impl AndroidHandle { pub fn empty() -> AndroidHandle { - #[allow(deprecated)] AndroidHandle { a_native_window: None, - _non_exhaustive_do_not_use: crate::seal::Seal, } } } diff --git a/src/ios.rs b/src/ios.rs index 1181daf..79d17a1 100644 --- a/src/ios.rs +++ b/src/ios.rs @@ -11,24 +11,20 @@ use core::ptr::NonNull; /// ..IOSHandle::empty() /// }; /// ``` +#[non_exhaustive] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct IOSHandle { pub ui_window: Option>, pub ui_view: Option>, pub ui_view_controller: Option>, - #[doc(hidden)] - #[deprecated = "This field is used to ensure that this struct is non-exhaustive, so that it may be extended in the future. Do not refer to this field."] - pub _non_exhaustive_do_not_use: crate::seal::Seal, } impl IOSHandle { pub fn empty() -> IOSHandle { - #[allow(deprecated)] IOSHandle { ui_window: None, ui_view: None, ui_view_controller: None, - _non_exhaustive_do_not_use: crate::seal::Seal, } } } diff --git a/src/lib.rs b/src/lib.rs index 75b5562..49b0fca 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -100,6 +100,7 @@ pub unsafe trait HasRawWindowHandle { fn raw_window_handle(&self) -> RawWindowHandle; } +#[non_exhaustive] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum RawWindowHandle { #[cfg_attr(feature = "nightly-docs", doc(cfg(target_os = "ios")))] @@ -195,15 +196,6 @@ pub enum RawWindowHandle { #[cfg_attr(feature = "nightly-docs", doc(cfg(target_os = "android")))] #[cfg_attr(not(feature = "nightly-docs"), cfg(target_os = "android"))] Android(android::AndroidHandle), - - #[doc(hidden)] - #[deprecated = "This field is used to ensure that this struct is non-exhaustive, so that it may be extended in the future. Do not refer to this field."] - __NonExhaustiveDoNotUse(seal::Seal), -} - -mod seal { - #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] - pub struct Seal; } /// This wraps a [`RawWindowHandle`] to give it a [`HasRawWindowHandle`] impl. diff --git a/src/macos.rs b/src/macos.rs index c4e0dff..90b91f5 100644 --- a/src/macos.rs +++ b/src/macos.rs @@ -11,23 +11,19 @@ use core::ptr::NonNull; /// ..MacOSHandle::empty() /// }; /// ``` +#[non_exhaustive] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct MacOSHandle { pub ns_window: Option>, pub ns_view: Option>, // TODO: WHAT ABOUT ns_window_controller and ns_view_controller? - #[doc(hidden)] - #[deprecated = "This field is used to ensure that this struct is non-exhaustive, so that it may be extended in the future. Do not refer to this field."] - pub _non_exhaustive_do_not_use: crate::seal::Seal, } impl MacOSHandle { pub fn empty() -> MacOSHandle { - #[allow(deprecated)] MacOSHandle { ns_window: None, ns_view: None, - _non_exhaustive_do_not_use: crate::seal::Seal, } } } diff --git a/src/unix.rs b/src/unix.rs index acbc7cd..353d569 100644 --- a/src/unix.rs +++ b/src/unix.rs @@ -13,15 +13,13 @@ use cty::c_ulong; /// ..XlibHandle::empty() /// }; /// ``` +#[non_exhaustive] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct XlibHandle { /// An Xlib `Window`. pub window: c_ulong, /// A pointer to an Xlib `Display`. pub display: *mut c_void, - #[doc(hidden)] - #[deprecated = "This field is used to ensure that this struct is non-exhaustive, so that it may be extended in the future. Do not refer to this field."] - pub _non_exhaustive_do_not_use: crate::seal::Seal, } /// Raw window handle for Xcb. @@ -34,15 +32,13 @@ pub struct XlibHandle { /// ..XcbHandle::empty() /// }; /// ``` +#[non_exhaustive] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct XcbHandle { /// An X11 `xcb_window_t`. pub window: u32, // Based on xproto.h /// A pointer to an X server `xcb_connection_t`. pub connection: *mut c_void, - #[doc(hidden)] - #[deprecated = "This field is used to ensure that this struct is non-exhaustive, so that it may be extended in the future. Do not refer to this field."] - pub _non_exhaustive_do_not_use: crate::seal::Seal, } /// Raw window handle for Wayland. @@ -55,46 +51,38 @@ pub struct XcbHandle { /// ..WaylandHandle::empty() /// }; /// ``` +#[non_exhaustive] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct WaylandHandle { /// A pointer to a `wl_surface`. pub surface: *mut c_void, /// A pointer to a `wl_display`. pub display: *mut c_void, - #[doc(hidden)] - #[deprecated = "This field is used to ensure that this struct is non-exhaustive, so that it may be extended in the future. Do not refer to this field."] - pub _non_exhaustive_do_not_use: crate::seal::Seal, } impl XlibHandle { pub fn empty() -> XlibHandle { - #[allow(deprecated)] XlibHandle { window: 0, display: ptr::null_mut(), - _non_exhaustive_do_not_use: crate::seal::Seal, } } } impl XcbHandle { pub fn empty() -> XcbHandle { - #[allow(deprecated)] XcbHandle { window: 0, connection: ptr::null_mut(), - _non_exhaustive_do_not_use: crate::seal::Seal, } } } impl WaylandHandle { pub fn empty() -> WaylandHandle { - #[allow(deprecated)] WaylandHandle { surface: ptr::null_mut(), display: ptr::null_mut(), - _non_exhaustive_do_not_use: crate::seal::Seal, } } } diff --git a/src/web.rs b/src/web.rs index 846d78c..f3b678e 100644 --- a/src/web.rs +++ b/src/web.rs @@ -8,6 +8,7 @@ /// ..WebHandle::empty() /// }; /// ``` +#[non_exhaustive] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct WebHandle { /// An ID value inserted into the data attributes of the canvas element as 'raw-handle' @@ -17,17 +18,10 @@ pub struct WebHandle { /// Each canvas created by the windowing system should be assigned their own unique ID. /// 0 should be reserved for invalid / null IDs. pub id: u32, - #[doc(hidden)] - #[deprecated = "This field is used to ensure that this struct is non-exhaustive, so that it may be extended in the future. Do not refer to this field."] - pub _non_exhaustive_do_not_use: crate::seal::Seal, } impl WebHandle { pub fn empty() -> WebHandle { - #[allow(deprecated)] - WebHandle { - id: 0, - _non_exhaustive_do_not_use: crate::seal::Seal, - } + WebHandle { id: 0 } } } diff --git a/src/windows.rs b/src/windows.rs index 43b6393..c6c327f 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -11,24 +11,20 @@ use core::ptr::NonNull; /// ..WindowsHandle::empty() /// }; /// ``` +#[non_exhaustive] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct WindowsHandle { /// A Win32 HWND handle. pub hwnd: Option>, /// The HINSTANCE associated with this type's HWND. pub hinstance: Option>, - #[doc(hidden)] - #[deprecated = "This field is used to ensure that this struct is non-exhaustive, so that it may be extended in the future. Do not refer to this field."] - pub _non_exhaustive_do_not_use: crate::seal::Seal, } impl WindowsHandle { pub fn empty() -> WindowsHandle { - #[allow(deprecated)] WindowsHandle { hwnd: None, hinstance: None, - _non_exhaustive_do_not_use: crate::seal::Seal, } } } From 47565e21878b891ba51255d1edb99c8bc03ff381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20du=20Garreau?= Date: Sun, 24 Jan 2021 15:35:04 +0100 Subject: [PATCH 2/2] Add #[non_exhaustive] to Redox and fix tests --- src/android.rs | 6 ++---- src/ios.rs | 6 ++---- src/macos.rs | 6 ++---- src/redox.rs | 13 +++---------- src/unix.rs | 18 ++++++------------ src/web.rs | 6 ++---- src/windows.rs | 6 ++---- 7 files changed, 19 insertions(+), 42 deletions(-) diff --git a/src/android.rs b/src/android.rs index 2cf849a..d3d4c4c 100644 --- a/src/android.rs +++ b/src/android.rs @@ -6,10 +6,8 @@ use core::ptr::NonNull; /// ## Construction /// ``` /// # use raw_window_handle::android::AndroidHandle; -/// let handle = AndroidHandle { -/// /* fields */ -/// ..AndroidHandle::empty() -/// }; +/// let mut handle = AndroidHandle::empty(); +/// /* set fields */ /// ``` #[non_exhaustive] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] diff --git a/src/ios.rs b/src/ios.rs index 79d17a1..b8c137f 100644 --- a/src/ios.rs +++ b/src/ios.rs @@ -6,10 +6,8 @@ use core::ptr::NonNull; /// ## Construction /// ``` /// # use raw_window_handle::ios::IOSHandle; -/// let handle = IOSHandle { -/// /* fields */ -/// ..IOSHandle::empty() -/// }; +/// let mut handle = IOSHandle::empty(); +/// /* set fields */ /// ``` #[non_exhaustive] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] diff --git a/src/macos.rs b/src/macos.rs index 90b91f5..f3e1909 100644 --- a/src/macos.rs +++ b/src/macos.rs @@ -6,10 +6,8 @@ use core::ptr::NonNull; /// ## Construction /// ``` /// # use raw_window_handle::macos::MacOSHandle; -/// let handle = MacOSHandle { -/// /* fields */ -/// ..MacOSHandle::empty() -/// }; +/// let mut handle = MacOSHandle::empty(); +/// /* set fields */ /// ``` #[non_exhaustive] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] diff --git a/src/redox.rs b/src/redox.rs index 1fe4155..124e127 100644 --- a/src/redox.rs +++ b/src/redox.rs @@ -6,27 +6,20 @@ use libc::c_void; /// ## Construction /// ``` /// # use raw_window_handle::redox::RedoxHandle; -/// let handle = RedoxHandle { -/// /* fields */ -/// ..RedoxHandle::empty() -/// }; +/// let mut handle = RedoxHandle::empty() +/// /* set fields */ /// ``` +#[non_exhaustive] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct RedoxHandle { /// A pointer to an orbclient window. pub window: *mut c_void, - - #[doc(hidden)] - #[deprecated = "This field is used to ensure that this struct is non-exhaustive, so that it may be extended in the future. Do not refer to this field."] - pub _non_exhaustive_do_not_use: crate::seal::Seal, } impl RedoxHandle { pub fn empty() -> RedoxHandle { - #[allow(deprecated)] RedoxHandle { window: ptr::null_mut(), - _non_exhaustive_do_not_use: crate::seal::Seal, } } } diff --git a/src/unix.rs b/src/unix.rs index 353d569..5a2764d 100644 --- a/src/unix.rs +++ b/src/unix.rs @@ -8,10 +8,8 @@ use cty::c_ulong; /// ## Construction /// ``` /// # use raw_window_handle::unix::XlibHandle; -/// let handle = XlibHandle { -/// /* fields */ -/// ..XlibHandle::empty() -/// }; +/// let handle = XlibHandle::empty(); +/// /* set fields */ /// ``` #[non_exhaustive] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -27,10 +25,8 @@ pub struct XlibHandle { /// ## Construction /// ``` /// # use raw_window_handle::unix::XcbHandle; -/// let handle = XcbHandle { -/// /* fields */ -/// ..XcbHandle::empty() -/// }; +/// let handle = XcbHandle::empty(); +/// /* set fields */ /// ``` #[non_exhaustive] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -46,10 +42,8 @@ pub struct XcbHandle { /// ## Construction /// ``` /// # use raw_window_handle::unix::WaylandHandle; -/// let handle = WaylandHandle { -/// /* fields */ -/// ..WaylandHandle::empty() -/// }; +/// let handle = WaylandHandle::empty(); +/// /* set fields */ /// ``` #[non_exhaustive] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] diff --git a/src/web.rs b/src/web.rs index f3b678e..90824d4 100644 --- a/src/web.rs +++ b/src/web.rs @@ -3,10 +3,8 @@ /// ## Construction /// ``` /// # use raw_window_handle::web::WebHandle; -/// let handle = WebHandle { -/// /* fields */ -/// ..WebHandle::empty() -/// }; +/// let mut handle = WebHandle::empty(); +/// /* set fields */ /// ``` #[non_exhaustive] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] diff --git a/src/windows.rs b/src/windows.rs index c6c327f..f297872 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -6,10 +6,8 @@ use core::ptr::NonNull; /// ## Construction /// ``` /// # use raw_window_handle::windows::WindowsHandle; -/// let handle = WindowsHandle { -/// /* fields */ -/// ..WindowsHandle::empty() -/// }; +/// let mut handle = WindowsHandle::empty(); +/// /* set fields */ /// ``` #[non_exhaustive] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]