From 769e8b60d55c7382ec61d04ff15c28de9c04c496 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Tue, 10 Nov 2020 19:56:05 +0100 Subject: [PATCH] event: Unwrap user event in map_nonuser_event Err() Currently separating an Event into a user event T and Event<()> is not ergonomic: when map_nonuser_event returns Err() the caller "knows" this can only contain UserEvent(T), yet has to write additional unpacking logic to extract the event, with an unnecessary unreachable!(). Solve this by returning T directly in the Err case, instead of Event<'a, T>. --- CHANGELOG.md | 1 + src/event.rs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28ecbf8320..a5d0049816 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - **Breaking:** On Web, remove the `stdweb` backend. - Added `Window::focus_window`to bring the window to the front and set input focus. - On Wayland and X11, implement `is_maximized` method on `Window`. +- **Breaking:** `map_nonuser_event` now returns the unwrapped user event `T` in `Err()`. # 0.25.0 (2021-05-15) diff --git a/src/event.rs b/src/event.rs index 4de6c36d5d..bdeb728c0b 100644 --- a/src/event.rs +++ b/src/event.rs @@ -143,10 +143,10 @@ impl Clone for Event<'static, T> { } impl<'a, T> Event<'a, T> { - pub fn map_nonuser_event(self) -> Result, Event<'a, T>> { + pub fn map_nonuser_event(self) -> Result, T> { use self::Event::*; match self { - UserEvent(_) => Err(self), + UserEvent(user_event) => Err(user_event), WindowEvent { window_id, event } => Ok(WindowEvent { window_id, event }), DeviceEvent { device_id, event } => Ok(DeviceEvent { device_id, event }), NewEvents(cause) => Ok(NewEvents(cause)),