Mark extensible enums in winit-core as #[non_exhaustive]

Event, input source, error, data transfer, native key, IME request,
scroll delta and fullscreen enums can now gain variants without a
breaking change. Backends and examples get wildcard arms where they
matched exhaustively; unknown IME requests are reported as
ImeRequestError::NotSupported and unknown fullscreen modes behave
like Fullscreen::Borderless(None).
This commit is contained in:
Olivier Goffart
2026-07-28 14:29:36 +00:00
parent 6a8a334426
commit 37d8a503e4
30 changed files with 57 additions and 21 deletions

View File

@@ -111,6 +111,7 @@ impl_dyn_casting!(CustomCursorProvider);
///
/// See [`CustomCursor`] for more details.
#[derive(Debug, Clone, Eq, Hash, PartialEq)]
#[non_exhaustive]
pub enum CustomCursorSource {
/// Cursor that is backed by RGBA image.
///
@@ -167,6 +168,7 @@ impl CustomCursorSource {
/// An error produced when using [`CustomCursorSource::from_rgba`] with invalid arguments.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub enum BadImage {
/// Produced when the image dimensions are larger than [`MAX_CURSOR_SIZE`]. This doesn't
/// guarantee that the cursor will work, but should avoid many platform and device specific
@@ -217,6 +219,7 @@ impl Error for BadImage {}
/// An error produced when using [`CustomCursorSource::from_animation`] with invalid arguments.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub enum BadAnimation {
/// Produced when no cursors were supplied.
Empty,

View File

@@ -127,6 +127,7 @@ impl DataTransferId {
/// The set of types supported cross-platform.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum TypeHint {
/// Plain UTF-8 text (see [`TypedData::try_as_string`]).
///
@@ -381,6 +382,7 @@ impl_dyn_casting!(DataTransfer);
/// different encoding on different platforms. To allow this to be represented, we allow
/// supplying strings and URIs separately from binary blobs.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum SendData {
/// List of URIs.
///

View File

@@ -20,6 +20,7 @@ use crate::window::{ActivationToken, Theme};
/// Describes the reason the event loop is resuming.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum StartCause {
/// Sent if the time specified by [`ControlFlow::WaitUntil`] has been reached. Contains the
/// moment the timeout was requested and the requested resume time. The actual resume time is
@@ -44,6 +45,7 @@ pub enum StartCause {
/// Describes an event from a [`Window`].
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub enum WindowEvent {
/// The activation token was delivered back and now could be used.
ActivationTokenDone { serial: AsyncRequestSerial, token: ActivationToken },
@@ -531,6 +533,7 @@ pub enum WindowEvent {
/// **Wayland/X11:** [`Unknown`](Self::Unknown) device types are converted to known variants by the
/// system.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum PointerKind {
Mouse,
/// See [`PointerSource::Touch`] for more details.
@@ -548,6 +551,7 @@ pub enum PointerKind {
/// **Wayland/X11:** [`Unknown`](Self::Unknown) device types are converted to known variants by the
/// system.
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum PointerSource {
Mouse,
/// Represents a touch event.
@@ -616,6 +620,7 @@ impl From<PointerSource> for PointerKind {
/// **Wayland/X11:** [`Unknown`](Self::Unknown) device types are converted to known variants by the
/// system.
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum ButtonSource {
/// ## Platform-specific
///
@@ -730,6 +735,7 @@ impl FingerId {
///
/// [window events]: WindowEvent
#[derive(Clone, Copy, Debug, PartialEq)]
#[non_exhaustive]
pub enum DeviceEvent {
/// Change in physical position of a pointing device.
///
@@ -1052,6 +1058,7 @@ impl From<ModifiersState> for Modifiers {
/// ```
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[non_exhaustive]
pub enum Ime {
/// Notifies when the IME was enabled.
///
@@ -1576,6 +1583,7 @@ impl From<TabletToolButton> for Option<MouseButton> {
/// Describes a difference in the mouse scroll wheel state.
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[non_exhaustive]
pub enum MouseScrollDelta {
/// Amount in lines or rows to scroll in the horizontal
/// and vertical directions.

View File

@@ -282,6 +282,7 @@ impl From<Icon> for DragIcon {
/// are expected to provide some kind of order of preference.
#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq)]
#[non_exhaustive]
pub enum DndAction {
/// Move the dragged item from the source to the destination.
///

View File

@@ -26,6 +26,7 @@ impl_dyn_casting!(IconProvider);
#[derive(Debug)]
/// An error produced when using [`RgbaIcon::new`] with invalid arguments.
#[non_exhaustive]
pub enum BadIcon {
/// Produced when the length of the `rgba` argument isn't divisible by 4, thus `rgba` can't be
/// safely interpreted as 32bpp RGBA pixels.

View File

@@ -19,6 +19,7 @@ pub use smol_str::SmolStr;
/// - On non-Web platforms, support assigning keybinds to virtually any key through a UI.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[non_exhaustive]
pub enum NativeKeyCode {
Unidentified,
/// An Android "scancode".
@@ -78,6 +79,7 @@ impl std::fmt::Debug for NativeKeyCode {
/// define keybinds which work in the presence of identifiers we haven't mapped for you yet.
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[non_exhaustive]
pub enum NativeKey {
Unidentified,
/// An Android "keycode", which is similar to a "virtual-key code" on Windows.

View File

@@ -183,6 +183,7 @@ impl fmt::Display for VideoMode {
/// Fullscreen modes.
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum Fullscreen {
Exclusive(MonitorHandle, VideoMode),

View File

@@ -1756,6 +1756,7 @@ bitflags! {
}
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
#[non_exhaustive]
pub enum ImeSurroundingTextError {
/// Text exceeds 4000 bytes
TextTooLong,
@@ -1868,6 +1869,7 @@ impl ImeSurroundingText {
/// Request to send to IME.
#[derive(Debug, PartialEq, Clone)]
#[non_exhaustive]
pub enum ImeRequest {
/// Enable the IME with the [`ImeCapabilities`] and [`ImeRequestData`] as initial state. When
/// the [`ImeRequestData`] is **not** matching capabilities fully, the default values will be