Skip to content

Commit e1d7be8

Browse files
authored
fix(example): runtime crash when counter less than 0 (#13955)
1 parent 90c1c32 commit e1d7be8

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

examples/state/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,31 @@ use std::sync::Mutex;
88

99
use tauri::State;
1010

11-
struct Counter(Mutex<usize>);
11+
struct Counter(Mutex<isize>);
1212

1313
#[tauri::command]
14-
fn increment(counter: State<'_, Counter>) -> usize {
14+
fn increment(counter: State<'_, Counter>) -> isize {
1515
let mut c = counter.0.lock().unwrap();
1616
*c += 1;
1717
*c
1818
}
1919

2020
#[tauri::command]
21-
fn decrement(counter: State<'_, Counter>) -> usize {
21+
fn decrement(counter: State<'_, Counter>) -> isize {
2222
let mut c = counter.0.lock().unwrap();
2323
*c -= 1;
2424
*c
2525
}
2626

2727
#[tauri::command]
28-
fn reset(counter: State<'_, Counter>) -> usize {
28+
fn reset(counter: State<'_, Counter>) -> isize {
2929
let mut c = counter.0.lock().unwrap();
3030
*c = 0;
3131
*c
3232
}
3333

3434
#[tauri::command]
35-
fn get(counter: State<'_, Counter>) -> usize {
35+
fn get(counter: State<'_, Counter>) -> isize {
3636
*counter.0.lock().unwrap()
3737
}
3838

0 commit comments

Comments
 (0)