mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-01-31 00:35:19 +01:00
fix(example): runtime crash when counter less than 0 (#13955)
This commit is contained in:
@@ -8,31 +8,31 @@ use std::sync::Mutex;
|
||||
|
||||
use tauri::State;
|
||||
|
||||
struct Counter(Mutex<usize>);
|
||||
struct Counter(Mutex<isize>);
|
||||
|
||||
#[tauri::command]
|
||||
fn increment(counter: State<'_, Counter>) -> usize {
|
||||
fn increment(counter: State<'_, Counter>) -> isize {
|
||||
let mut c = counter.0.lock().unwrap();
|
||||
*c += 1;
|
||||
*c
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn decrement(counter: State<'_, Counter>) -> usize {
|
||||
fn decrement(counter: State<'_, Counter>) -> isize {
|
||||
let mut c = counter.0.lock().unwrap();
|
||||
*c -= 1;
|
||||
*c
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn reset(counter: State<'_, Counter>) -> usize {
|
||||
fn reset(counter: State<'_, Counter>) -> isize {
|
||||
let mut c = counter.0.lock().unwrap();
|
||||
*c = 0;
|
||||
*c
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn get(counter: State<'_, Counter>) -> usize {
|
||||
fn get(counter: State<'_, Counter>) -> isize {
|
||||
*counter.0.lock().unwrap()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user