Skip to content

Commit

Permalink
rename TimerHandle to Timer
Browse files Browse the repository at this point in the history
  • Loading branch information
micahrj committed Oct 27, 2023
1 parent 27fa5fc commit a4d0e46
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 29 deletions.
14 changes: 7 additions & 7 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down Expand Up @@ -117,12 +117,12 @@ impl<'a, T: 'static> AppContext<'a, T> {
}
}

pub fn set_timer<H>(&self, duration: Duration, handler: H) -> TimerHandle
pub fn set_timer<H>(&self, duration: Duration, handler: H) -> Timer
where
H: 'static,
H: FnMut(&mut T, &AppContext<T>),
{
TimerHandle {
Timer {
inner: self.inner.set_timer(duration, handler),
_marker: PhantomData,
}
Expand Down
4 changes: 2 additions & 2 deletions src/backend/cocoa/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -149,7 +149,7 @@ impl<'a, T: 'static> AppContextInner<'a, T> {
}
}

pub fn set_timer<H>(&self, duration: Duration, handler: H) -> TimerHandleInner
pub fn set_timer<H>(&self, duration: Duration, handler: H) -> TimerInner
where
H: 'static,
H: FnMut(&mut T, &AppContext<T>),
Expand Down
2 changes: 1 addition & 1 deletion src/backend/cocoa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
8 changes: 4 additions & 4 deletions src/backend/cocoa/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl Timers {
app_state: &Rc<AppState>,
duration: Duration,
handler: H,
) -> TimerHandleInner
) -> TimerInner
where
T: 'static,
H: 'static,
Expand Down Expand Up @@ -108,7 +108,7 @@ impl Timers {
CFRunLoopAddTimer(run_loop, timer, kCFRunLoopCommonModes);
}

TimerHandleInner {
TimerInner {
app_state: Rc::downgrade(app_state),
timer,
}
Expand All @@ -126,12 +126,12 @@ impl Drop for Timers {
}
}

pub struct TimerHandleInner {
pub struct TimerInner {
app_state: Weak<AppState>,
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) {
Expand Down
4 changes: 2 additions & 2 deletions src/backend/win32/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -263,7 +263,7 @@ impl<'a, T: 'static> AppContextInner<'a, T> {
}
}

pub fn set_timer<H>(&self, duration: Duration, handler: H) -> TimerHandleInner
pub fn set_timer<H>(&self, duration: Duration, handler: H) -> TimerInner
where
H: 'static,
H: FnMut(&mut T, &AppContext<T>),
Expand Down
2 changes: 1 addition & 1 deletion src/backend/win32/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/backend/win32/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl Timers {
app_state: &Rc<AppState>,
duration: Duration,
handler: H,
) -> TimerHandleInner
) -> TimerInner
where
T: 'static,
H: 'static,
Expand Down Expand Up @@ -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,
}
Expand All @@ -85,12 +85,12 @@ impl Timers {
}
}

pub struct TimerHandleInner {
pub struct TimerInner {
app_state: Weak<AppState>,
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) {
Expand Down
4 changes: 2 additions & 2 deletions src/backend/x11/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -274,7 +274,7 @@ impl<'a, T: 'static> AppContextInner<'a, T> {
}
}

pub fn set_timer<H>(&self, duration: Duration, handler: H) -> TimerHandleInner
pub fn set_timer<H>(&self, duration: Duration, handler: H) -> TimerInner
where
H: 'static,
H: FnMut(&mut T, &AppContext<T>),
Expand Down
2 changes: 1 addition & 1 deletion src/backend/x11/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
8 changes: 4 additions & 4 deletions src/backend/x11/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl Timers {
app_state: &Rc<AppState>,
duration: Duration,
handler: H,
) -> TimerHandleInner
) -> TimerInner
where
T: 'static,
H: 'static,
Expand Down Expand Up @@ -96,7 +96,7 @@ impl Timers {
timer_id,
});

TimerHandleInner {
TimerInner {
app_state: Rc::downgrade(app_state),
timer_id,
}
Expand Down Expand Up @@ -125,12 +125,12 @@ impl Timers {
}
}

pub struct TimerHandleInner {
pub struct TimerInner {
app_state: Weak<AppState>,
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);
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit a4d0e46

Please sign in to comment.