Skip to content

Commit 8a3fd3b

Browse files
fredmorcosCobrand
authored andcommitted
Add a #[must_use] directive to add_timer()
If the result of add_timer is unused, the timer will be dropped immediately and the callback won't fire. A small gotcha but can save some debugging time.
1 parent e9f2e33 commit 8a3fd3b

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

src/sdl2/timer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ impl TimerSubsystem {
1313
///
1414
/// * when the timer is dropped
1515
/// * or when the callback returns a non-positive continuation interval
16+
#[must_use = "if unused the Timer will be dropped immediately"]
1617
pub fn add_timer<'b, 'c>(&'b self, delay: u32, callback: TimerCallback<'c>) -> Timer<'b, 'c> {
1718
unsafe {
1819
let callback = Box::new(callback);

0 commit comments

Comments
 (0)