Skip to content

Commit df52554

Browse files
committed
fix code
1 parent 2e117ed commit df52554

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

chapter3/src/3_9_2/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
use rand::Rng;
12
use std::fs::File;
23
use std::io;
34
use std::io::Write;
45

56
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);
79

810
let mut file = File::create("random.txt")?;
911
file.write_all(&bytes)?;

chapter3/src/3_9_5/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ where
2020
}
2121

2222
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+
));
2427
let mut new_file = File::create("new_test.txt")?;
2528

2629
copy_n(&mut file, &mut new_file, 4)?;

0 commit comments

Comments
 (0)