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 11mod drone_repository_tests;
22mod flight_controller_tests;
3+ mod generator_tests;
34mod 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>> {
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+ }
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments