Skip to content

Commit c7fd0e4

Browse files
committed
Rustfmt
1 parent ce156a3 commit c7fd0e4

File tree

4 files changed

+13
-27
lines changed

4 files changed

+13
-27
lines changed

exercises/24_file_io/file_io1.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::path::Path;
33

44
const TEST_FILE_NAME: &str = "SampleTextFile.txt";
55
fn main() {
6-
76
create_required_files();
87

98
let read_str_result = fs::read_to_string(TEST_FILE_NAME);
@@ -20,13 +19,11 @@ fn main() {
2019
}
2120
}
2221

23-
24-
fn create_required_files(){
22+
fn create_required_files() {
2523
let file_path = Path::new(TEST_FILE_NAME);
2624

2725
if file_path.exists() == false {
2826
fs::write(&file_path, "This is the file content.").unwrap();
2927
println!("File created.");
3028
}
31-
32-
}
29+
}

solutions/24_file_io/file_io1.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::path::Path;
33

44
const TEST_FILE_NAME: &str = "SampleTextFile.txt";
55
fn main() {
6-
76
create_required_files();
87

98
let read_str_result = fs::read_to_string(TEST_FILE_NAME);
@@ -14,18 +13,15 @@ fn main() {
1413
}
1514
Err(_) => {
1615
panic!("Error reading file.");
17-
1816
}
1917
}
2018
}
2119

22-
23-
fn create_required_files(){
20+
fn create_required_files() {
2421
let file_path = Path::new(TEST_FILE_NAME);
2522

2623
if !file_path.exists() {
2724
fs::write(file_path, "This is the file content.").unwrap();
2825
println!("File created.");
2926
}
30-
31-
}
27+
}

solutions/24_file_io/file_io2.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ fn main() {
2626
let mut buffered_file_writer = BufWriter::new(output_file.ok().unwrap());
2727

2828
let mut line_number = 1;
29-
29+
3030
for line in buffered_input_file.lines() {
3131
if let Ok(line) = line {
32-
let write_result =buffered_file_writer.write(format!("Line {} : {}\n", line_number, line).as_bytes());
32+
let write_result =
33+
buffered_file_writer.write(format!("Line {} : {}\n", line_number, line).as_bytes());
3334
if write_result.is_err() {
3435
eprintln!("Write result error: {}", write_result.unwrap_err());
3536
break;

solutions/24_file_io/file_io3.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use std::fs;
2-
use std::path::{PathBuf};
2+
use std::path::PathBuf;
33

44
fn main() {
5-
65
create_required_files();
76
let mut path_buffer = PathBuf::new();
87

@@ -18,33 +17,26 @@ fn main() {
1817
assert_eq!(meta_data.len(), 117);
1918
println!("File permissions {:?}", meta_data.permissions());
2019
assert!(!meta_data.permissions().readonly());
21-
}else {
20+
} else {
2221
panic!("Could not get metadata");
23-
2422
}
25-
26-
27-
28-
2923
}
3024

31-
fn create_required_files(){
25+
fn create_required_files() {
3226
let file_path = PathBuf::from("SampleFilesFolder/MultiLineTextFile.txt");
3327

3428
let dir_path = file_path.parent().unwrap();
3529

36-
if !dir_path.exists() {
30+
if !dir_path.exists() {
3731
fs::create_dir(dir_path).unwrap();
3832
println!("Created directory {:?}", dir_path);
3933
}
4034

41-
if !file_path.exists(){
42-
35+
if !file_path.exists() {
4336
let text = "This is the first line of the text.
4437
This is the second line.
4538
And this is the third and the last line.";
4639
fs::write(file_path, text).unwrap();
4740
println!("File created.");
4841
}
49-
50-
}
42+
}

0 commit comments

Comments
 (0)