@@ -19,6 +19,7 @@ use std::env;
1919use std:: io:: { self , Error , ErrorKind } ;
2020use std:: fs;
2121use std:: path:: { self , PathBuf , Path } ;
22+ use std:: ffi:: { OsStr , OsString } ;
2223use rand:: { thread_rng, Rng } ;
2324
2425/// A wrapper for a path to temporary directory implementing automatic
@@ -42,7 +43,7 @@ impl TempDir {
4243 /// deleted once the returned wrapper is destroyed.
4344 ///
4445 /// If no directory can be created, `Err` is returned.
45- pub fn new_in < P : AsRef < Path > > ( tmpdir : P , prefix : & str )
46+ pub fn new_in < P : AsRef < Path > , N : AsRef < OsStr > > ( tmpdir : P , prefix : N )
4647 -> io:: Result < TempDir > {
4748 let storage;
4849 let mut tmpdir = tmpdir. as_ref ( ) ;
@@ -56,13 +57,18 @@ impl TempDir {
5657 let mut rng = thread_rng ( ) ;
5758 for _ in 0 ..NUM_RETRIES {
5859 let suffix: String = rng. gen_ascii_chars ( ) . take ( NUM_RAND_CHARS ) . collect ( ) ;
59- let leaf = if prefix. len ( ) > 0 {
60- format ! ( "{}.{}" , prefix, suffix)
60+ let pv = prefix. as_ref ( ) ;
61+ let leaf = if pv != OsStr :: new ( "" ) {
62+ let mut s = OsString :: new ( ) ;
63+ s. push ( pv) ;
64+ s. push ( "." ) ;
65+ s. push ( suffix) ;
66+ s
6167 } else {
6268 // If we're given an empty string for a prefix, then creating a
6369 // directory starting with "." would lead to it being
6470 // semi-invisible on some systems.
65- suffix
71+ OsString :: from ( suffix)
6672 } ;
6773 let path = tmpdir. join ( & leaf) ;
6874 match fs:: create_dir ( & path) {
0 commit comments