diff --git a/src/app.rs b/src/app.rs index f32fda8..8549e34 100644 --- a/src/app.rs +++ b/src/app.rs @@ -4,6 +4,7 @@ use std::{fmt, result}; use crate::{backend, IntoInnerError, Result}; +#[derive(Clone)] pub struct Timer { inner: backend::TimerInner, // ensure !Send and !Sync on all platforms @@ -11,7 +12,7 @@ pub struct Timer { } impl Timer { - pub fn cancel(self) { + pub fn cancel(&self) { self.inner.cancel(); } } diff --git a/src/backend/cocoa/timer.rs b/src/backend/cocoa/timer.rs index 8d79b3c..a1751a9 100644 --- a/src/backend/cocoa/timer.rs +++ b/src/backend/cocoa/timer.rs @@ -126,13 +126,14 @@ impl Drop for Timers { } } +#[derive(Clone)] pub struct TimerInner { app_state: Weak, 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 { diff --git a/src/backend/win32/timer.rs b/src/backend/win32/timer.rs index 1358e01..31eda92 100644 --- a/src/backend/win32/timer.rs +++ b/src/backend/win32/timer.rs @@ -85,13 +85,14 @@ impl Timers { } } +#[derive(Clone)] pub struct TimerInner { app_state: Weak, 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 { diff --git a/src/backend/x11/timer.rs b/src/backend/x11/timer.rs index fcb628e..eda3a4a 100644 --- a/src/backend/x11/timer.rs +++ b/src/backend/x11/timer.rs @@ -125,13 +125,14 @@ impl Timers { } } +#[derive(Clone)] pub struct TimerInner { app_state: Weak, 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); }