@@ -9,25 +9,6 @@ use winreg::{
9
9
RegKey , RegValue ,
10
10
} ;
11
11
12
- /// Support testing of code that mutates global state
13
- #[ cfg( windows) ]
14
- fn with_saved_global_state < S > (
15
- getter : impl Fn ( ) -> io:: Result < S > ,
16
- setter : impl Fn ( S ) ,
17
- f : & mut dyn FnMut ( ) ,
18
- ) {
19
- // Lock protects concurrent mutation of registry
20
- static LOCK : Mutex < ( ) > = Mutex :: new ( ( ) ) ;
21
- let _g = LOCK . lock ( ) ;
22
-
23
- // Save and restore the global state here to keep from trashing things.
24
- let saved_state =
25
- getter ( ) . expect ( "Error getting global state: Better abort to avoid trashing it" ) ;
26
- let _g = scopeguard:: guard ( saved_state, setter) ;
27
-
28
- f ( ) ;
29
- }
30
-
31
12
#[ cfg( windows) ]
32
13
pub fn with_saved_path ( f : & mut dyn FnMut ( ) ) {
33
14
with_saved_reg_value ( & RegKey :: predef ( HKEY_CURRENT_USER ) , "Environment" , "PATH" , f)
@@ -45,11 +26,16 @@ pub fn get_path() -> io::Result<Option<RegValue>> {
45
26
46
27
#[ cfg( windows) ]
47
28
pub fn with_saved_reg_value ( root : & RegKey , subkey : & str , name : & str , f : & mut dyn FnMut ( ) ) {
48
- with_saved_global_state (
49
- || get_reg_value ( root, subkey, name) ,
50
- |p| restore_reg_value ( root, subkey, name, p) ,
51
- f,
52
- )
29
+ // Lock protects concurrent mutation of registry
30
+ static LOCK : Mutex < ( ) > = Mutex :: new ( ( ) ) ;
31
+ let _g = LOCK . lock ( ) ;
32
+
33
+ // Save and restore the global state here to keep from trashing things.
34
+ let saved_state = get_reg_value ( root, subkey, name)
35
+ . expect ( "Error getting global state: Better abort to avoid trashing it" ) ;
36
+ let _g = scopeguard:: guard ( saved_state, |p| restore_reg_value ( root, subkey, name, p) ) ;
37
+
38
+ f ( ) ;
53
39
}
54
40
55
41
#[ cfg( windows) ]
0 commit comments