File tree Expand file tree Collapse file tree 3 files changed +42
-1
lines changed Expand file tree Collapse file tree 3 files changed +42
-1
lines changed Original file line number Diff line number Diff line change 1
1
mod drone_repository_tests;
2
2
mod flight_controller_tests;
3
+ mod generator_tests;
3
4
mod simulation_loader_tests;
4
- mod generator_tests;
Original file line number Diff line number Diff line change @@ -51,3 +51,37 @@ pub fn read_games_from_file() -> io::Result<Vec<String>> {
51
51
}
52
52
Ok ( games)
53
53
}
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
+ }
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ fn main() -> std::io::Result<()> {
16
16
let new_game = read_game_from_stdin ( ) ?;
17
17
classic_games. push ( new_game) ;
18
18
print_games_to_stdout ( & classic_games) ;
19
+ println ! ( "\n \n " ) ;
19
20
20
21
let games = load_games ( ) ;
21
22
write_games_to_file ( & games) ?;
@@ -24,5 +25,11 @@ fn main() -> std::io::Result<()> {
24
25
println ! ( "{}" , game) ;
25
26
}
26
27
28
+ println ! ( "\n \n " ) ;
29
+ let games = read_games_to_vec ( ) ?;
30
+ for game in games {
31
+ println ! ( "{}" , game) ;
32
+ }
33
+
27
34
Ok ( ( ) )
28
35
}
You can’t perform that action at this time.
0 commit comments