From a4d0e46367c71387ff1e840e7f9eb5c035c4d541 Mon Sep 17 00:00:00 2001 From: Micah Johnston Date: Thu, 26 Oct 2023 23:34:48 -0500 Subject: [PATCH] rename TimerHandle to Timer --- src/app.rs | 14 +++++++------- src/backend/cocoa/app.rs | 4 ++-- src/backend/cocoa/mod.rs | 2 +- src/backend/cocoa/timer.rs | 8 ++++---- src/backend/win32/app.rs | 4 ++-- src/backend/win32/mod.rs | 2 +- src/backend/win32/timer.rs | 8 ++++---- src/backend/x11/app.rs | 4 ++-- src/backend/x11/mod.rs | 2 +- src/backend/x11/timer.rs | 8 ++++---- src/lib.rs | 2 +- 11 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/app.rs b/src/app.rs index 211ec98..f32fda8 100644 --- a/src/app.rs +++ b/src/app.rs @@ -4,21 +4,21 @@ use std::{fmt, result}; use crate::{backend, IntoInnerError, Result}; -pub struct TimerHandle { - inner: backend::TimerHandleInner, +pub struct Timer { + inner: backend::TimerInner, // ensure !Send and !Sync on all platforms _marker: PhantomData<*mut ()>, } -impl TimerHandle { +impl Timer { pub fn cancel(self) { self.inner.cancel(); } } -impl fmt::Debug for TimerHandle { +impl fmt::Debug for Timer { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - fmt.debug_struct("TimerHandle").finish_non_exhaustive() + fmt.debug_struct("Timer").finish_non_exhaustive() } } @@ -117,12 +117,12 @@ impl<'a, T: 'static> AppContext<'a, T> { } } - pub fn set_timer(&self, duration: Duration, handler: H) -> TimerHandle + pub fn set_timer(&self, duration: Duration, handler: H) -> Timer where H: 'static, H: FnMut(&mut T, &AppContext), { - TimerHandle { + Timer { inner: self.inner.set_timer(duration, handler), _marker: PhantomData, } diff --git a/src/backend/cocoa/app.rs b/src/backend/cocoa/app.rs index a692b97..6c02b4d 100644 --- a/src/backend/cocoa/app.rs +++ b/src/backend/cocoa/app.rs @@ -14,7 +14,7 @@ use icrate::AppKit::{NSApplication, NSApplicationActivationPolicyRegular, NSCurs use icrate::Foundation::{NSPoint, NSSize, NSThread}; use super::display_links::DisplayLinks; -use super::timer::{TimerHandleInner, Timers}; +use super::timer::{TimerInner, Timers}; use super::window::View; use crate::{App, AppContext, AppMode, AppOptions, Error, IntoInnerError, Result}; @@ -149,7 +149,7 @@ impl<'a, T: 'static> AppContextInner<'a, T> { } } - pub fn set_timer(&self, duration: Duration, handler: H) -> TimerHandleInner + pub fn set_timer(&self, duration: Duration, handler: H) -> TimerInner where H: 'static, H: FnMut(&mut T, &AppContext), diff --git a/src/backend/cocoa/mod.rs b/src/backend/cocoa/mod.rs index 38aee00..21dd3e4 100644 --- a/src/backend/cocoa/mod.rs +++ b/src/backend/cocoa/mod.rs @@ -8,7 +8,7 @@ mod timer; mod window; pub use app::{AppContextInner, AppInner}; -pub use timer::TimerHandleInner; +pub use timer::TimerInner; pub use window::WindowInner; #[derive(Debug)] diff --git a/src/backend/cocoa/timer.rs b/src/backend/cocoa/timer.rs index 1b40292..8d79b3c 100644 --- a/src/backend/cocoa/timer.rs +++ b/src/backend/cocoa/timer.rs @@ -60,7 +60,7 @@ impl Timers { app_state: &Rc, duration: Duration, handler: H, - ) -> TimerHandleInner + ) -> TimerInner where T: 'static, H: 'static, @@ -108,7 +108,7 @@ impl Timers { CFRunLoopAddTimer(run_loop, timer, kCFRunLoopCommonModes); } - TimerHandleInner { + TimerInner { app_state: Rc::downgrade(app_state), timer, } @@ -126,12 +126,12 @@ impl Drop for Timers { } } -pub struct TimerHandleInner { +pub struct TimerInner { app_state: Weak, timer: CFRunLoopTimerRef, } -impl TimerHandleInner { +impl TimerInner { pub fn cancel(self) { if let Some(app_state) = self.app_state.upgrade() { if app_state.timers.timers.borrow_mut().remove(&self.timer) { diff --git a/src/backend/win32/app.rs b/src/backend/win32/app.rs index 85f6729..96d97c7 100644 --- a/src/backend/win32/app.rs +++ b/src/backend/win32/app.rs @@ -17,7 +17,7 @@ use windows::Win32::UI::WindowsAndMessaging::{ }; use super::dpi::DpiFns; -use super::timer::{TimerHandleInner, Timers}; +use super::timer::{TimerInner, Timers}; use super::vsync::VsyncThreads; use super::window::{self, WindowState}; use super::{class_name, hinstance, to_wstring, WM_USER_VBLANK}; @@ -263,7 +263,7 @@ impl<'a, T: 'static> AppContextInner<'a, T> { } } - pub fn set_timer(&self, duration: Duration, handler: H) -> TimerHandleInner + pub fn set_timer(&self, duration: Duration, handler: H) -> TimerInner where H: 'static, H: FnMut(&mut T, &AppContext), diff --git a/src/backend/win32/mod.rs b/src/backend/win32/mod.rs index 89e8991..750eb75 100644 --- a/src/backend/win32/mod.rs +++ b/src/backend/win32/mod.rs @@ -13,7 +13,7 @@ mod vsync; mod window; pub use app::{AppContextInner, AppInner}; -pub use timer::TimerHandleInner; +pub use timer::TimerInner; pub use window::WindowInner; use crate::Error; diff --git a/src/backend/win32/timer.rs b/src/backend/win32/timer.rs index f326d25..1358e01 100644 --- a/src/backend/win32/timer.rs +++ b/src/backend/win32/timer.rs @@ -31,7 +31,7 @@ impl Timers { app_state: &Rc, duration: Duration, handler: H, - ) -> TimerHandleInner + ) -> TimerInner where T: 'static, H: 'static, @@ -59,7 +59,7 @@ impl Timers { SetTimer(app_state.message_hwnd, timer_id, millis, None); } - TimerHandleInner { + TimerInner { app_state: Rc::downgrade(app_state), timer_id, } @@ -85,12 +85,12 @@ impl Timers { } } -pub struct TimerHandleInner { +pub struct TimerInner { app_state: Weak, timer_id: usize, } -impl TimerHandleInner { +impl TimerInner { pub fn cancel(self) { if let Some(app_state) = self.app_state.upgrade() { if let Some(_) = app_state.timers.timers.borrow_mut().remove(&self.timer_id) { diff --git a/src/backend/x11/app.rs b/src/backend/x11/app.rs index f6f95a0..d346b1d 100644 --- a/src/backend/x11/app.rs +++ b/src/backend/x11/app.rs @@ -12,7 +12,7 @@ use x11rb::protocol::{shm, xproto}; use x11rb::rust_connection::RustConnection; use x11rb::{cursor, protocol, resource_manager}; -use super::timer::{TimerHandleInner, Timers}; +use super::timer::{TimerInner, Timers}; use super::window::WindowState; use crate::{ App, AppContext, AppOptions, Cursor, Event, IntoInnerError, MouseButton, Point, Rect, Result, @@ -274,7 +274,7 @@ impl<'a, T: 'static> AppContextInner<'a, T> { } } - pub fn set_timer(&self, duration: Duration, handler: H) -> TimerHandleInner + pub fn set_timer(&self, duration: Duration, handler: H) -> TimerInner where H: 'static, H: FnMut(&mut T, &AppContext), diff --git a/src/backend/x11/mod.rs b/src/backend/x11/mod.rs index a7d4a62..2657f3f 100644 --- a/src/backend/x11/mod.rs +++ b/src/backend/x11/mod.rs @@ -5,5 +5,5 @@ mod window; pub use app::{AppContextInner, AppInner}; pub use error::OsError; -pub use timer::TimerHandleInner; +pub use timer::TimerInner; pub use window::WindowInner; diff --git a/src/backend/x11/timer.rs b/src/backend/x11/timer.rs index ae6ac85..fcb628e 100644 --- a/src/backend/x11/timer.rs +++ b/src/backend/x11/timer.rs @@ -65,7 +65,7 @@ impl Timers { app_state: &Rc, duration: Duration, handler: H, - ) -> TimerHandleInner + ) -> TimerInner where T: 'static, H: 'static, @@ -96,7 +96,7 @@ impl Timers { timer_id, }); - TimerHandleInner { + TimerInner { app_state: Rc::downgrade(app_state), timer_id, } @@ -125,12 +125,12 @@ impl Timers { } } -pub struct TimerHandleInner { +pub struct TimerInner { app_state: Weak, timer_id: TimerId, } -impl TimerHandleInner { +impl TimerInner { pub fn cancel(self) { if let Some(app_state) = self.app_state.upgrade() { app_state.timers.timers.borrow_mut().remove(&self.timer_id); diff --git a/src/lib.rs b/src/lib.rs index 9eb8f56..4c9f585 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,7 +3,7 @@ mod backend; mod error; mod window; -pub use app::{App, AppContext, AppMode, AppOptions, TimerHandle}; +pub use app::{App, AppContext, AppMode, AppOptions, Timer}; pub use error::{Error, IntoInnerError, Result}; pub use window::{ Bitmap, Cursor, Event, MouseButton, Point, RawParent, Rect, Response, Size, Window,