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
use std::os::raw::c_int;
#[allow(unused_assignments)]
pub fn add_shutdown_hook(callback: extern fn()) -> bool {
let mut result: c_int = 0;
unsafe {
result = atexit(callback);
}
if result == 0 {
return true;
} else {
return false;
}
}
extern {
fn atexit(callback: extern fn()) -> c_int;
}
#[allow(unused_imports)]
mod tests {
use super::add_shutdown_hook;
#[test]
fn test_add_shutdown_hook_should_work() {
assert!(add_shutdown_hook(get_in_the_bowl));
}
#[allow(dead_code)]
extern fn get_in_the_bowl() {
assert!(1 + 2 == 3);
}
}