@@ -19,6 +19,7 @@ use std::env;
19
19
use std:: io:: { self , Error , ErrorKind } ;
20
20
use std:: fs;
21
21
use std:: path:: { self , PathBuf , Path } ;
22
+ use std:: ffi:: { OsStr , OsString } ;
22
23
use rand:: { thread_rng, Rng } ;
23
24
24
25
/// A wrapper for a path to temporary directory implementing automatic
@@ -42,7 +43,7 @@ impl TempDir {
42
43
/// deleted once the returned wrapper is destroyed.
43
44
///
44
45
/// 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 )
46
47
-> io:: Result < TempDir > {
47
48
let storage;
48
49
let mut tmpdir = tmpdir. as_ref ( ) ;
@@ -56,13 +57,18 @@ impl TempDir {
56
57
let mut rng = thread_rng ( ) ;
57
58
for _ in 0 ..NUM_RETRIES {
58
59
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
61
67
} else {
62
68
// If we're given an empty string for a prefix, then creating a
63
69
// directory starting with "." would lead to it being
64
70
// semi-invisible on some systems.
65
- suffix
71
+ OsString :: from ( suffix)
66
72
} ;
67
73
let path = tmpdir. join ( & leaf) ;
68
74
match fs:: create_dir ( & path) {
0 commit comments