1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use Result;
use restart;
use error;
use thread;
use cratesleep;
/// Handles program failure by restarting the device.
///
/// This function waits for a second and then restarts the device if the program encounters an error.
!
/// Runs the main application logic with automatic error logging and device restart on exit.
///
/// This function wraps the provided closure to ensure the device restarts
/// if the program exits. Any errors are logged with their full chain
/// before the restart occurs.
///
/// # Arguments
/// * `f` - A closure that returns a `Result`.
///
/// # Type Parameters
/// * `F` - The type of the closure.
///
/// # Returns
/// Never returns normally - either runs forever or restarts the device.
!
where
F: FnOnce ,
/// A guard that ensures the program restarts on thread exit.
;
/// Spawns a new thread with a failure guard.
///
/// # Arguments
/// * `f` - A closure to execute in the new thread.
///
/// # Returns
/// A `JoinHandle` for the spawned thread.
///
/// # Type Parameters
/// * `F` - The type of the closure.
/// * `T` - The return type of the closure.