@@ -109,24 +109,19 @@ impl ProcMacroLibraryLibloading {
109109 }
110110}
111111
112- type ProcMacroLibraryImpl = ProcMacroLibraryLibloading ;
113-
114112pub struct Expander {
115- inner : ProcMacroLibraryImpl ,
113+ inner : ProcMacroLibraryLibloading ,
116114}
117115
118116impl Expander {
119- pub fn new ( lib : & Path ) -> Result < Expander , String > {
117+ pub fn new ( lib : & Path ) -> io :: Result < Expander > {
120118 // Some libraries for dynamic loading require canonicalized path even when it is
121119 // already absolute
122- let lib = lib
123- . canonicalize ( )
124- . unwrap_or_else ( |err| panic ! ( "Cannot canonicalize {}: {:?}" , lib. display( ) , err) ) ;
120+ let lib = lib. canonicalize ( ) ?;
125121
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) ?;
128123
129- let library = ProcMacroLibraryImpl :: open ( & lib) . map_err ( |e| e . to_string ( ) ) ?;
124+ let library = ProcMacroLibraryLibloading :: open ( & lib) ?;
130125
131126 Ok ( Expander { inner : library } )
132127 }
@@ -199,8 +194,9 @@ impl Expander {
199194 }
200195}
201196
197+ /// Copy the dylib to temp directory to prevent locking in Windows
202198#[ 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 > {
204200 let mut to = std:: env:: temp_dir ( ) ;
205201 let file_name = path. file_name ( ) . ok_or_else ( || {
206202 io:: Error :: new (
@@ -215,6 +211,6 @@ fn copy_to_temp_dir(path: &Path) -> io::Result<PathBuf> {
215211}
216212
217213#[ 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 > {
219215 Ok ( path. to_path_buf ( ) )
220216}
0 commit comments