@@ -109,24 +109,19 @@ impl ProcMacroLibraryLibloading {
109
109
}
110
110
}
111
111
112
- type ProcMacroLibraryImpl = ProcMacroLibraryLibloading ;
113
-
114
112
pub struct Expander {
115
- inner : ProcMacroLibraryImpl ,
113
+ inner : ProcMacroLibraryLibloading ,
116
114
}
117
115
118
116
impl Expander {
119
- pub fn new ( lib : & Path ) -> Result < Expander , String > {
117
+ pub fn new ( lib : & Path ) -> io :: Result < Expander > {
120
118
// Some libraries for dynamic loading require canonicalized path even when it is
121
119
// already absolute
122
- let lib = lib
123
- . canonicalize ( )
124
- . unwrap_or_else ( |err| panic ! ( "Cannot canonicalize {}: {:?}" , lib. display( ) , err) ) ;
120
+ let lib = lib. canonicalize ( ) ?;
125
121
126
- // Copy the dylib to temp directory to prevent locking in Windows
127
- let lib = copy_to_temp_dir ( & lib) . map_err ( |e| e. to_string ( ) ) ?;
122
+ let lib = ensure_file_with_lock_free_access ( & lib) ?;
128
123
129
- let library = ProcMacroLibraryImpl :: open ( & lib) . map_err ( |e| e . to_string ( ) ) ?;
124
+ let library = ProcMacroLibraryLibloading :: open ( & lib) ?;
130
125
131
126
Ok ( Expander { inner : library } )
132
127
}
@@ -199,8 +194,9 @@ impl Expander {
199
194
}
200
195
}
201
196
197
+ /// Copy the dylib to temp directory to prevent locking in Windows
202
198
#[ cfg( windows) ]
203
- fn copy_to_temp_dir ( path : & Path ) -> io:: Result < PathBuf > {
199
+ fn ensure_file_with_lock_free_access ( path : & Path ) -> io:: Result < PathBuf > {
204
200
let mut to = std:: env:: temp_dir ( ) ;
205
201
let file_name = path. file_name ( ) . ok_or_else ( || {
206
202
io:: Error :: new (
@@ -215,6 +211,6 @@ fn copy_to_temp_dir(path: &Path) -> io::Result<PathBuf> {
215
211
}
216
212
217
213
#[ cfg( unix) ]
218
- fn copy_to_temp_dir ( path : & Path ) -> io:: Result < PathBuf > {
214
+ fn ensure_file_with_lock_free_access ( path : & Path ) -> io:: Result < PathBuf > {
219
215
Ok ( path. to_path_buf ( ) )
220
216
}
0 commit comments