@@ -18,6 +18,7 @@ extern crate rand;
1818
1919use std:: env;
2020use std:: io:: { self , Error , ErrorKind } ;
21+ use std:: ffi:: { AsOsStr , OsStr , OsString } ;
2122use std:: fs;
2223use std:: path:: { self , PathBuf , AsPath } ;
2324use rand:: { thread_rng, Rng } ;
@@ -43,7 +44,7 @@ impl TempDir {
4344 /// deleted once the returned wrapper is destroyed.
4445 ///
4546 /// If no directory can be created, `Err` is returned.
46- pub fn new_in < P : AsPath + ?Sized > ( tmpdir : & P , prefix : & str )
47+ pub fn new_in < P : AsPath + ?Sized , N : AsOsStr + ? Sized > ( tmpdir : & P , prefix : & N )
4748 -> io:: Result < TempDir > {
4849 let storage;
4950 let mut tmpdir = tmpdir. as_path ( ) ;
@@ -57,13 +58,17 @@ impl TempDir {
5758 let mut rng = thread_rng ( ) ;
5859 for _ in 0 ..NUM_RETRIES {
5960 let suffix: String = rng. gen_ascii_chars ( ) . take ( NUM_RAND_CHARS ) . collect ( ) ;
60- let leaf = if prefix. len ( ) > 0 {
61- format ! ( "{}.{}" , prefix, suffix)
61+ let leaf = if prefix. as_os_str ( ) != OsStr :: from_str ( "" ) {
62+ let mut s = OsString :: new ( ) ;
63+ s. push ( prefix. as_os_str ( ) ) ;
64+ s. push ( OsStr :: from_str ( "." ) ) ;
65+ s. push ( suffix. as_os_str ( ) ) ;
66+ s
6267 } else {
6368 // If we're given an empty string for a prefix, then creating a
6469 // directory starting with "." would lead to it being
6570 // semi-invisible on some systems.
66- suffix
71+ suffix. as_os_str ( ) . to_os_string ( )
6772 } ;
6873 let path = tmpdir. join ( & leaf) ;
6974 match fs:: create_dir ( & path) {
0 commit comments