From cc6d8d893ed78d0798e873e11eca481673e8fe7a Mon Sep 17 00:00:00 2001 From: daxpedda Date: Mon, 4 Sep 2023 11:35:12 +0200 Subject: [PATCH] Address review --- CHANGELOG.md | 2 +- src/event.rs | 2 +- src/event_loop.rs | 10 +++++----- src/platform_impl/android/mod.rs | 10 +++++----- src/platform_impl/ios/event_loop.rs | 2 +- src/platform_impl/linux/mod.rs | 4 ++-- src/platform_impl/linux/wayland/event_loop/mod.rs | 6 +++--- src/platform_impl/linux/wayland/output.rs | 2 +- src/platform_impl/linux/x11/mod.rs | 8 ++++---- src/platform_impl/macos/app_state.rs | 8 ++++---- src/platform_impl/macos/event_loop.rs | 6 +++--- src/platform_impl/orbital/event_loop.rs | 4 ++-- src/platform_impl/web/event_loop/runner.rs | 8 ++++---- src/platform_impl/web/event_loop/state.rs | 2 +- src/platform_impl/web/event_loop/window_target.rs | 4 ++-- src/platform_impl/windows/event_loop.rs | 2 +- 16 files changed, 40 insertions(+), 40 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 145a251cb9..9002d24854 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,7 +21,7 @@ And please only add new entries to the top of this list, right below the `# Unre - Mark `startup_notify` unsafe functions as safe. - Fix a bug where Wayland would be chosen on Linux even if the user specified `with_x11`. (#3058) - **Breaking:** Moved `ControlFlow` to `EventLoopWindowTarget::set_control_flow()` and `EventLoopWindowTarget::control_flow()`. -- **Breaking:** Moved `ControlFlow::Exit` to `EventLoopWindowTarget::set_exit()` and `EventLoopWindowTarget::is_exit()` and removed `ControlFlow::ExitWithCode(_)` entirely. +- **Breaking:** Moved `ControlFlow::Exit` to `EventLoopWindowTarget::set_exit()` and `EventLoopWindowTarget::exiting()` and removed `ControlFlow::ExitWithCode(_)` entirely. # 0.29.1-beta diff --git a/src/event.rs b/src/event.rs index dbfaf02a6e..16c46c98d8 100644 --- a/src/event.rs +++ b/src/event.rs @@ -9,7 +9,7 @@ //! ```rust,ignore //! let mut start_cause = StartCause::Init; //! -//! while !elwt.is_exit() { +//! while !elwt.exiting() { //! event_handler(NewEvents(start_cause), elwt); //! //! for e in (window events, user events, device events) { diff --git a/src/event_loop.rs b/src/event_loop.rs index 5a300a9043..9c2c02a9b4 100644 --- a/src/event_loop.rs +++ b/src/event_loop.rs @@ -175,7 +175,7 @@ pub enum ControlFlow { } impl ControlFlow { - /// Sets this to wait until a timeout has expired. + /// Creates a [`ControlFlow`] that waits until a timeout has expired. /// /// In most cases, this is set to [`WaitUntil`]. However, if the timeout overflows, it is /// instead set to [`Wait`]. @@ -320,9 +320,9 @@ impl EventLoopWindowTarget { self.p.control_flow() } - /// Send a [`LoopExiting`] event and stop the event loop. + /// This exits the event loop. /// - /// [`LoopExiting`]: Event::LoopExiting + /// See [`LoopExiting`](Event::LoopExiting). pub fn exit(&self) { self.p.exit() } @@ -330,8 +330,8 @@ impl EventLoopWindowTarget { /// Returns if the [`EventLoop`] is about to stop. /// /// See [`exit()`](Self::exit). - pub fn is_exit(&self) -> bool { - self.p.is_exit() + pub fn exiting(&self) -> bool { + self.p.exiting() } } diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index d050cfd0af..aadf5cbb37 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -534,10 +534,10 @@ impl EventLoop { // Consider the possibility that the `StartCause::Init` iteration could // request to Exit - if !self.is_exit() { + if !self.exiting() { self.poll_events_with_timeout(timeout, &mut callback); } - if self.is_exit() { + if self.exiting() { self.loop_running = false; callback(event::Event::LoopExiting, self.window_target()); @@ -645,8 +645,8 @@ impl EventLoop { self.window_target.p.control_flow() } - fn is_exit(&self) -> bool { - self.window_target.p.is_exit() + fn exiting(&self) -> bool { + self.window_target.p.exiting() } } @@ -712,7 +712,7 @@ impl EventLoopWindowTarget { self.exit.set(true) } - pub(crate) fn is_exit(&self) -> bool { + pub(crate) fn exiting(&self) -> bool { self.exit.get() } } diff --git a/src/platform_impl/ios/event_loop.rs b/src/platform_impl/ios/event_loop.rs index fe1086624b..883acfc8a4 100644 --- a/src/platform_impl/ios/event_loop.rs +++ b/src/platform_impl/ios/event_loop.rs @@ -70,7 +70,7 @@ impl EventLoopWindowTarget { warn!("`ControlFlow::Exit` ignored on iOS"); } - pub(crate) fn is_exit(&self) -> bool { + pub(crate) fn exiting(&self) -> bool { false } } diff --git a/src/platform_impl/linux/mod.rs b/src/platform_impl/linux/mod.rs index aebc2fcc95..4a52f88ce7 100644 --- a/src/platform_impl/linux/mod.rs +++ b/src/platform_impl/linux/mod.rs @@ -858,8 +858,8 @@ impl EventLoopWindowTarget { x11_or_wayland!(match self; Self(evlp) => evlp.exit()) } - pub(crate) fn is_exit(&self) -> bool { - x11_or_wayland!(match self; Self(evlp) => evlp.is_exit()) + pub(crate) fn exiting(&self) -> bool { + x11_or_wayland!(match self; Self(evlp) => evlp.exiting()) } fn set_exit_code(&self, code: i32) { diff --git a/src/platform_impl/linux/wayland/event_loop/mod.rs b/src/platform_impl/linux/wayland/event_loop/mod.rs index 13f17598f7..ceb8588e92 100644 --- a/src/platform_impl/linux/wayland/event_loop/mod.rs +++ b/src/platform_impl/linux/wayland/event_loop/mod.rs @@ -238,7 +238,7 @@ impl EventLoop { // Consider the possibility that the `StartCause::Init` iteration could // request to Exit. - if !self.is_exit() { + if !self.exiting() { self.poll_events_with_timeout(timeout, &mut callback); } if let Some(code) = self.exit_code() { @@ -619,8 +619,8 @@ impl EventLoop { self.window_target.p.control_flow() } - fn is_exit(&self) -> bool { - self.window_target.p.is_exit() + fn exiting(&self) -> bool { + self.window_target.p.exiting() } fn set_exit_code(&self, code: i32) { diff --git a/src/platform_impl/linux/wayland/output.rs b/src/platform_impl/linux/wayland/output.rs index e87a062f3d..b8547e6b0d 100644 --- a/src/platform_impl/linux/wayland/output.rs +++ b/src/platform_impl/linux/wayland/output.rs @@ -37,7 +37,7 @@ impl EventLoopWindowTarget { self.exit.set(Some(0)) } - pub(crate) fn is_exit(&self) -> bool { + pub(crate) fn exiting(&self) -> bool { self.exit.get().is_some() } diff --git a/src/platform_impl/linux/x11/mod.rs b/src/platform_impl/linux/x11/mod.rs index 8bc600d60d..6be647826b 100644 --- a/src/platform_impl/linux/x11/mod.rs +++ b/src/platform_impl/linux/x11/mod.rs @@ -450,7 +450,7 @@ impl EventLoop { // Consider the possibility that the `StartCause::Init` iteration could // request to Exit. - if !self.is_exit() { + if !self.exiting() { self.poll_events_with_timeout(timeout, &mut callback); } if let Some(code) = self.exit_code() { @@ -649,8 +649,8 @@ impl EventLoop { self.target.p.control_flow() } - fn is_exit(&self) -> bool { - self.target.p.is_exit() + fn exiting(&self) -> bool { + self.target.p.exiting() } fn set_exit_code(&self, code: i32) { @@ -727,7 +727,7 @@ impl EventLoopWindowTarget { self.exit.set(Some(0)) } - pub(crate) fn is_exit(&self) -> bool { + pub(crate) fn exiting(&self) -> bool { self.exit.get().is_some() } diff --git a/src/platform_impl/macos/app_state.rs b/src/platform_impl/macos/app_state.rs index 2cf9aa3af5..bc9b04c1b8 100644 --- a/src/platform_impl/macos/app_state.rs +++ b/src/platform_impl/macos/app_state.rs @@ -210,7 +210,7 @@ impl Handler { self.exit.store(true, Ordering::Relaxed) } - pub fn is_exit(&self) -> bool { + pub fn exiting(&self) -> bool { self.exit.load(Ordering::Relaxed) } @@ -429,8 +429,8 @@ impl AppState { HANDLER.exit() } - pub fn is_exit() -> bool { - HANDLER.is_exit() + pub fn exiting() -> bool { + HANDLER.exiting() } pub fn dispatch_init_events() { @@ -640,7 +640,7 @@ impl AppState { HANDLER.handle_nonuser_event(Event::AboutToWait); HANDLER.set_in_callback(false); - if HANDLER.is_exit() { + if HANDLER.exiting() { Self::stop(); } diff --git a/src/platform_impl/macos/event_loop.rs b/src/platform_impl/macos/event_loop.rs index b67c698714..422d5ca402 100644 --- a/src/platform_impl/macos/event_loop.rs +++ b/src/platform_impl/macos/event_loop.rs @@ -106,8 +106,8 @@ impl EventLoopWindowTarget { AppState::exit() } - pub(crate) fn is_exit(&self) -> bool { - AppState::is_exit() + pub(crate) fn exiting(&self) -> bool { + AppState::exiting() } } @@ -418,7 +418,7 @@ impl EventLoop { resume_unwind(panic); } - if AppState::is_exit() { + if AppState::exiting() { AppState::internal_exit(); PumpStatus::Exit(0) } else { diff --git a/src/platform_impl/orbital/event_loop.rs b/src/platform_impl/orbital/event_loop.rs index 531b477339..cd64a9228f 100644 --- a/src/platform_impl/orbital/event_loop.rs +++ b/src/platform_impl/orbital/event_loop.rs @@ -598,7 +598,7 @@ impl EventLoop { event_handler(event::Event::AboutToWait, &self.window_target); - if self.window_target.p.is_exit() { + if self.window_target.p.exiting() { break; } @@ -752,7 +752,7 @@ impl EventLoopWindowTarget { self.exit.set(true); } - pub(crate) fn is_exit(&self) -> bool { + pub(crate) fn exiting(&self) -> bool { self.exit.get() } } diff --git a/src/platform_impl/web/event_loop/runner.rs b/src/platform_impl/web/event_loop/runner.rs index b5a48edb00..081458753d 100644 --- a/src/platform_impl/web/event_loop/runner.rs +++ b/src/platform_impl/web/event_loop/runner.rs @@ -610,7 +610,7 @@ impl Shared { RunnerEnum::Destroyed => return, } - let is_closed = self.is_exit(); + let is_closed = self.exiting(); // Don't take events out of the queue if the loop is closed or the runner doesn't exist // If the runner doesn't exist and this method recurses, it will recurse infinitely @@ -627,7 +627,7 @@ impl Shared { // Apply the new ControlFlow that has been selected by the user // Start any necessary timeouts etc fn apply_control_flow(&self) { - let new_state = if self.is_exit() { + let new_state = if self.exiting() { State::Exit } else { match self.control_flow() { @@ -713,7 +713,7 @@ impl Shared { // Check if the event loop is currently closed fn is_closed(&self) -> bool { match self.0.runner.try_borrow().as_ref().map(Deref::deref) { - Ok(RunnerEnum::Running(runner)) => runner.state.is_exit(), + Ok(RunnerEnum::Running(runner)) => runner.state.exiting(), // The event loop is not closed since it is not initialized. Ok(RunnerEnum::Pending) => false, // The event loop is closed since it has been destroyed. @@ -766,7 +766,7 @@ impl Shared { self.0.exit.set(true) } - pub(crate) fn is_exit(&self) -> bool { + pub(crate) fn exiting(&self) -> bool { self.0.exit.get() } } diff --git a/src/platform_impl/web/event_loop/state.rs b/src/platform_impl/web/event_loop/state.rs index d5b5cad501..8a354c78c4 100644 --- a/src/platform_impl/web/event_loop/state.rs +++ b/src/platform_impl/web/event_loop/state.rs @@ -20,7 +20,7 @@ pub enum State { } impl State { - pub fn is_exit(&self) -> bool { + pub fn exiting(&self) -> bool { matches!(self, State::Exit) } } diff --git a/src/platform_impl/web/event_loop/window_target.rs b/src/platform_impl/web/event_loop/window_target.rs index a2e548980a..82308a9659 100644 --- a/src/platform_impl/web/event_loop/window_target.rs +++ b/src/platform_impl/web/event_loop/window_target.rs @@ -691,7 +691,7 @@ impl EventLoopWindowTarget { self.runner.exit() } - pub(crate) fn is_exit(&self) -> bool { - self.runner.is_exit() + pub(crate) fn exiting(&self) -> bool { + self.runner.exiting() } } diff --git a/src/platform_impl/windows/event_loop.rs b/src/platform_impl/windows/event_loop.rs index 4b3dd97501..b5a15ba3c7 100644 --- a/src/platform_impl/windows/event_loop.rs +++ b/src/platform_impl/windows/event_loop.rs @@ -554,7 +554,7 @@ impl EventLoopWindowTarget { self.runner_shared.set_exit_code(0) } - pub(crate) fn is_exit(&self) -> bool { + pub(crate) fn exiting(&self) -> bool { self.runner_shared.exit_code().is_some() }