Skip to content

Commit

Permalink
event: Unwrap user event in map_nonuser_event Err()
Browse files Browse the repository at this point in the history
Currently separating an Event<T> 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>.
  • Loading branch information
MarijnS95 committed Nov 10, 2020
1 parent cbeb51b commit 4ec0b4a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Unreleased

- On Android, calling `WindowEvent::Focused` now works properly instead of always returning false.
- On Android, calling `WindowEvent::Focused` now works properly instead of always returning false.
- On Windows, fix alt-tab behaviour by removing borderless fullscreen "always on top" flag.
- On Windows, fix bug preventing windows with transparency enabled from having fully-opaque regions.
- **Breaking:** On Windows, include prefix byte in scancodes.
Expand All @@ -10,6 +10,7 @@
- On Web, fix `WindowEvent::ReceivedCharacter` never being sent on key input.
- On macOS, fix compilation when targeting aarch64
- On X11, fix `Window::request_redraw` not waking the event loop.
- **Breaking:** `map_nonuser_event` now returns the unwrapped user event `T` in `Err()`.

# 0.23.0 (2020-10-02)

Expand Down
4 changes: 2 additions & 2 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ impl<T: Clone> Clone for Event<'static, T> {
}

impl<'a, T> Event<'a, T> {
pub fn map_nonuser_event<U>(self) -> Result<Event<'a, U>, Event<'a, T>> {
pub fn map_nonuser_event<U>(self) -> Result<Event<'a, U>, 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)),
Expand Down

0 comments on commit 4ec0b4a

Please sign in to comment.