@@ -36,46 +36,48 @@ impl Leaderboard {
3636 * self . total_matches += 1 ;
3737 }
3838
39- pub fn get_total_matches ( & mut self ) -> Vec < u8 > {
39+ pub fn get_total_matches ( & self ) -> Vec < u8 > {
4040 ( * self . total_matches ) . to_string ( ) . into_bytes ( )
4141 }
4242
4343 pub fn record_match ( & mut self , player : String , match_id : u64 , score : u16 , opponent : String ) {
44- self . players . with_mut ( player, |matches| {
45- matches. with_mut ( match_id, |m| {
44+ if let Some ( matches ) = self . players . get_mut ( player. clone ( ) ) {
45+ if let Some ( m ) = matches. get_mut ( match_id) {
4646 * m. score = score;
4747 * m. opponent = opponent;
48- } ) ;
49- } ) ;
48+ }
49+ }
5050 * self . total_matches += 1 ;
5151 }
5252
53- pub fn get_match_score ( & mut self , player : String , match_id : u64 ) -> Vec < u8 > {
54- self . players . with_mut ( player, |matches| {
55- matches. with_mut ( match_id, |m| {
56- ( * m. score ) . to_string ( ) . into_bytes ( )
57- } )
58- } )
53+ pub fn get_match_score ( & self , player : String , match_id : u64 ) -> Vec < u8 > {
54+ if let Some ( matches) = self . players . get ( player) {
55+ if let Some ( m) = matches. get ( match_id) {
56+ return ( * m. score ) . to_string ( ) . into_bytes ( ) ;
57+ }
58+ }
59+ "0" . to_string ( ) . into_bytes ( )
5960 }
6061
61- pub fn get_match_opponent ( & mut self , player : String , match_id : u64 ) -> String {
62- self . players . with_mut ( player, |matches| {
63- matches. with_mut ( match_id, |m| {
64- ( * m. opponent ) . clone ( )
65- } )
66- } )
62+ pub fn get_match_opponent ( & self , player : String , match_id : u64 ) -> String {
63+ if let Some ( matches) = self . players . get ( player) {
64+ if let Some ( m) = matches. get ( match_id) {
65+ return ( * m. opponent ) . clone ( ) ;
66+ }
67+ }
68+ String :: new ( )
6769 }
6870
6971 pub fn set_tournament_info ( & mut self , name : String , prize_pool : u64 ) {
7072 * self . tournament . name = name;
7173 * self . tournament . prize_pool = prize_pool;
7274 }
7375
74- pub fn get_tournament_name ( & mut self ) -> String {
76+ pub fn get_tournament_name ( & self ) -> String {
7577 ( * self . tournament . name ) . clone ( )
7678 }
7779
78- pub fn get_tournament_prize ( & mut self ) -> Vec < u8 > {
80+ pub fn get_tournament_prize ( & self ) -> Vec < u8 > {
7981 ( * self . tournament . prize_pool ) . to_string ( ) . into_bytes ( )
8082 }
8183
@@ -87,7 +89,7 @@ impl Leaderboard {
8789 }
8890 }
8991
90- pub fn get_player_wins ( & mut self , player : String ) -> Vec < u8 > {
92+ pub fn get_player_wins ( & self , player : String ) -> Vec < u8 > {
9193 if let Some ( wins) = self . player_wins . get ( & player) {
9294 ( * wins) . to_string ( ) . into_bytes ( )
9395 } else {
0 commit comments