File tree Expand file tree Collapse file tree 2 files changed +7
-2
lines changed Expand file tree Collapse file tree 2 files changed +7
-2
lines changed Original file line number Diff line number Diff line change
1
+ use rand:: Rng ;
1
2
use std:: fs:: File ;
2
3
use std:: io;
3
4
use std:: io:: Write ;
4
5
5
6
fn main ( ) -> io:: Result < ( ) > {
6
- let bytes = rand:: thread_rng ( ) . gen :: < [ u8 ; 1024 ] > ( ) ;
7
+ let mut bytes = [ 0u8 ; 1024 ] ;
8
+ rand:: thread_rng ( ) . fill ( & mut bytes) ;
7
9
8
10
let mut file = File :: create ( "random.txt" ) ?;
9
11
file. write_all ( & bytes) ?;
Original file line number Diff line number Diff line change 20
20
}
21
21
22
22
fn main ( ) -> Result < ( ) > {
23
- let mut file = File :: open ( "test.txt" ) . expect ( r#"動作には4バイト以上の "{}/test.txt" が必要です。"# , std:: env:: current_dir ( ) ?. display ( ) ) ;
23
+ let mut file = File :: open ( "test.txt" ) . expect ( & format ! (
24
+ "動作には4バイト以上の {}/test.txt が必要です" ,
25
+ std:: env:: current_dir( ) ?. display( )
26
+ ) ) ;
24
27
let mut new_file = File :: create ( "new_test.txt" ) ?;
25
28
26
29
copy_n ( & mut file, & mut new_file, 4 ) ?;
You can’t perform that action at this time.
0 commit comments