Skip to content

Commit 3ccf088

Browse files
authored
Merge pull request #33 from k-nasa/replace_3_9_section
implement chapter3_9 other than problem 3_9_6
2 parents b6359c3 + 3d0d247 commit 3ccf088

File tree

7 files changed

+393
-0
lines changed

7 files changed

+393
-0
lines changed

Cargo.lock

+260
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chapter3/Cargo.toml

+17
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,25 @@ edition = "2018"
77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

99
[dependencies]
10+
rand = "0.8.3"
11+
zip = "0.5.12"
1012
lib = { path = "../lib" }
1113

1214
[[bin]]
1315
name = "main_3_1"
1416
path = "src/3_1/main.rs"
17+
[[bin]]
18+
name = "3_9_1"
19+
path = "src/3_9_1/main.rs"
20+
[[bin]]
21+
name = "3_9_2"
22+
path = "src/3_9_2/main.rs"
23+
[[bin]]
24+
name = "3_9_3"
25+
path = "src/3_9_3/main.rs"
26+
[[bin]]
27+
name = "3_9_4"
28+
path = "src/3_9_4/main.rs"
29+
[[bin]]
30+
name = "3_9_5"
31+
path = "src/3_9_5/main.rs"

chapter3/src/3_9_1/main.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use std::env;
2+
use std::fs::File;
3+
use std::io;
4+
5+
fn main() -> io::Result<()> {
6+
let args: Vec<_> = env::args().collect();
7+
8+
let src = &args[1];
9+
let dest = &args[2];
10+
11+
let mut file = File::open(src)?;
12+
let mut new_file = File::create(dest)?;
13+
14+
io::copy(&mut file, &mut new_file)?;
15+
16+
Ok(())
17+
}

chapter3/src/3_9_2/main.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use rand::Rng;
2+
use std::fs::File;
3+
use std::io;
4+
use std::io::Write;
5+
6+
fn main() -> io::Result<()> {
7+
let mut bytes = [0u8; 1024];
8+
rand::thread_rng().fill(&mut bytes);
9+
10+
let mut file = File::create("random.txt")?;
11+
file.write_all(&bytes)?;
12+
13+
Ok(())
14+
}

chapter3/src/3_9_3/main.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use std::fs::File;
2+
use std::io;
3+
use std::io::Write;
4+
5+
fn main() -> io::Result<()> {
6+
let file = File::create("file.zip")?;
7+
8+
let mut zip = zip::ZipWriter::new(file);
9+
zip.start_file("file.txt", zip::write::FileOptions::default())?;
10+
zip.write_all(b"zipzipzipzipzipzipzipzipzipzipzipzipzipzipzipzip")?;
11+
12+
Ok(())
13+
}

0 commit comments

Comments
 (0)