@@ -17,7 +17,7 @@ use ops::Drop;
17
17
use option:: Option ;
18
18
use option:: Option :: { None , Some } ;
19
19
use os;
20
- use path:: { Path , GenericPath } ;
20
+ use path:: { Path , GenericPath , BytesContainer } ;
21
21
use result:: Result :: { Ok , Err } ;
22
22
use sync:: atomic;
23
23
@@ -34,7 +34,7 @@ impl TempDir {
34
34
/// deleted once the returned wrapper is destroyed.
35
35
///
36
36
/// If no directory can be created, `Err` is returned.
37
- pub fn new_in ( tmpdir : & Path , suffix : & str ) -> IoResult < TempDir > {
37
+ pub fn new_in < T : BytesContainer > ( tmpdir : & Path , suffix : T ) -> IoResult < TempDir > {
38
38
if !tmpdir. is_absolute ( ) {
39
39
let abs_tmpdir = try!( os:: make_absolute ( tmpdir) ) ;
40
40
return TempDir :: new_in ( & abs_tmpdir, suffix) ;
@@ -44,11 +44,13 @@ impl TempDir {
44
44
45
45
let mut attempts = 0 u;
46
46
loop {
47
- let filename =
48
- format ! ( "rs-{}-{}-{} " ,
47
+ let prefix =
48
+ format ! ( "rs-{}-{}-" ,
49
49
unsafe { libc:: getpid( ) } ,
50
- CNT . fetch_add( 1 , atomic:: SeqCst ) ,
51
- suffix) ;
50
+ CNT . fetch_add( 1 , atomic:: SeqCst ) ) ;
51
+
52
+ let mut filename = prefix. into_bytes ( ) ;
53
+ filename. push_all ( suffix. container_as_bytes ( ) ) ;
52
54
let p = tmpdir. join ( filename) ;
53
55
match fs:: mkdir ( & p, io:: USER_RWX ) {
54
56
Err ( error) => {
@@ -67,7 +69,7 @@ impl TempDir {
67
69
/// deleted once the returned wrapper is destroyed.
68
70
///
69
71
/// If no directory can be created, `Err` is returned.
70
- pub fn new ( suffix : & str ) -> IoResult < TempDir > {
72
+ pub fn new < T : BytesContainer > ( suffix : T ) -> IoResult < TempDir > {
71
73
TempDir :: new_in ( & os:: tmpdir ( ) , suffix)
72
74
}
73
75
0 commit comments