Skip to content

Commit b78bf77

Browse files
committed
Refactored
1 parent 00a18df commit b78bf77

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

drone-lab/src/tests/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
mod drone_repository_tests;
22
mod flight_controller_tests;
3+
mod generator_tests;
34
mod simulation_loader_tests;
4-
mod generator_tests;

fops/src/io_ops.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,37 @@ pub fn read_games_from_file() -> io::Result<Vec<String>> {
5151
}
5252
Ok(games)
5353
}
54+
55+
/*
56+
Bu metot games.data dosyasındaki içeriği alıp, satırları | işaretine göre ayrıştırıp
57+
geriye Game türünden bir Vector nesnesi döndürür.
58+
*/
59+
pub fn read_games_to_vec() -> io::Result<Vec<Game>> {
60+
let mut games = Vec::new();
61+
62+
for line in read_games_from_file()? {
63+
let cols: Vec<&str> = line.split('|').collect();
64+
if cols.len() != 3 {
65+
return Err(io::Error::new(
66+
io::ErrorKind::InvalidData,
67+
format!("Beklenmeyen sütun sayısı: `{}`", line),
68+
));
69+
}
70+
71+
let title = cols[0].to_string();
72+
let year = cols[1]
73+
.parse::<u16>()
74+
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
75+
let popularity = cols[2]
76+
.parse::<f32>()
77+
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
78+
79+
games.push(Game {
80+
title,
81+
year,
82+
popularity,
83+
});
84+
}
85+
86+
Ok(games)
87+
}

fops/src/main.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ fn main() -> std::io::Result<()> {
1616
let new_game = read_game_from_stdin()?;
1717
classic_games.push(new_game);
1818
print_games_to_stdout(&classic_games);
19+
println!("\n\n");
1920

2021
let games = load_games();
2122
write_games_to_file(&games)?;
@@ -24,5 +25,11 @@ fn main() -> std::io::Result<()> {
2425
println!("{}", game);
2526
}
2627

28+
println!("\n\n");
29+
let games = read_games_to_vec()?;
30+
for game in games {
31+
println!("{}", game);
32+
}
33+
2734
Ok(())
2835
}

0 commit comments

Comments
 (0)