File tree Expand file tree Collapse file tree 1 file changed +2
-18
lines changed Expand file tree Collapse file tree 1 file changed +2
-18
lines changed Original file line number Diff line number Diff line change 1
1
//! Write format string to a file using `write!` macro (Go version uses `Fprintf`).
2
2
3
3
use std:: {
4
- env:: temp_dir,
5
4
fmt,
6
5
fs:: File ,
7
6
io:: { self , Read , Write } ,
8
- path:: PathBuf ,
9
- time:: { SystemTime , UNIX_EPOCH } ,
10
7
} ;
11
8
12
- fn mktemp ( ) -> PathBuf {
13
- let mut tempdir = temp_dir ( ) ;
14
-
15
- let tempfile = {
16
- let now = SystemTime :: now ( ) ;
17
- let unixtime = now
18
- . duration_since ( UNIX_EPOCH )
19
- . expect ( "system clock maybe corrupt" ) ;
20
- format ! ( "{}-{:09}" , unixtime. as_secs( ) , unixtime. subsec_nanos( ) )
21
- } ;
22
-
23
- tempdir. push ( tempfile) ;
24
- tempdir
25
- }
9
+ use lib:: env:: temp_file;
26
10
27
11
fn write_fmt < W : fmt:: Write > ( w : & mut W ) {
28
12
write ! (
@@ -34,7 +18,7 @@ fn write_fmt<W: fmt::Write>(w: &mut W) {
34
18
}
35
19
36
20
fn main ( ) -> io:: Result < ( ) > {
37
- let tmp_path = mktemp ( ) ;
21
+ let tmp_path = temp_file ( ) ;
38
22
{
39
23
let mut contents = String :: new ( ) ;
40
24
write_fmt ( & mut contents) ;
You can’t perform that action at this time.
0 commit comments