Skip to content

Commit

Permalink
impl Clone for Timer; make Timer::cancel take &self
Browse files Browse the repository at this point in the history
  • Loading branch information
micahrj committed Oct 27, 2023
1 parent a4d0e46 commit 243c60d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ use std::{fmt, result};

use crate::{backend, IntoInnerError, Result};

#[derive(Clone)]
pub struct Timer {
inner: backend::TimerInner,
// ensure !Send and !Sync on all platforms
_marker: PhantomData<*mut ()>,
}

impl Timer {
pub fn cancel(self) {
pub fn cancel(&self) {
self.inner.cancel();
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/backend/cocoa/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,14 @@ impl Drop for Timers {
}
}

#[derive(Clone)]
pub struct TimerInner {
app_state: Weak<AppState>,
timer: CFRunLoopTimerRef,
}

impl TimerInner {
pub fn cancel(self) {
pub fn cancel(&self) {
if let Some(app_state) = self.app_state.upgrade() {
if app_state.timers.timers.borrow_mut().remove(&self.timer) {
unsafe {
Expand Down
3 changes: 2 additions & 1 deletion src/backend/win32/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,14 @@ impl Timers {
}
}

#[derive(Clone)]
pub struct TimerInner {
app_state: Weak<AppState>,
timer_id: usize,
}

impl TimerInner {
pub fn cancel(self) {
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) {
unsafe {
Expand Down
3 changes: 2 additions & 1 deletion src/backend/x11/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,14 @@ impl Timers {
}
}

#[derive(Clone)]
pub struct TimerInner {
app_state: Weak<AppState>,
timer_id: TimerId,
}

impl TimerInner {
pub fn cancel(self) {
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

0 comments on commit 243c60d

Please sign in to comment.