@@ -34,7 +34,7 @@ fn main() {
3434 _ => {
3535 id = id_arg
3636 . parse :: < u32 > ( )
37- . expect ( & format ! ( "not a number: {}" , id_arg) ) ;
37+ . unwrap_or_else ( |_| panic ! ( "not a number: {}" , id_arg) ) ;
3838 if solved_ids. contains ( & id) {
3939 println ! (
4040 "The problem you chose is invalid (the problem may have been solved \
@@ -45,16 +45,14 @@ fn main() {
4545 }
4646 }
4747
48- let problem = problem:: get_problem ( id) . expect ( & format ! (
49- "Error: failed to get problem #{} \
50- (The problem may be paid-only or may not be exist).",
51- id
52- ) ) ;
53- let code = problem
54- . code_definition
55- . iter ( )
56- . filter ( |& d| d. value == "rust" )
57- . next ( ) ;
48+ let problem = problem:: get_problem ( id) . unwrap_or_else ( || {
49+ panic ! (
50+ "Error: failed to get problem #{} \
51+ (The problem may be paid-only or may not be exist).",
52+ id
53+ )
54+ } ) ;
55+ let code = problem. code_definition . iter ( ) . find ( |& d| d. value == "rust" ) ;
5856 if code. is_none ( ) {
5957 println ! ( "Problem {} has no rust version." , & id) ;
6058 solved_ids. push ( problem. question_id ) ;
@@ -100,7 +98,7 @@ fn main() {
10098 }
10199}
102100
103- fn generate_random_id ( except_ids : & Vec < u32 > ) -> u32 {
101+ fn generate_random_id ( except_ids : & [ u32 ] ) -> u32 {
104102 use rand:: Rng ;
105103 use std:: fs;
106104 let mut rng = rand:: thread_rng ( ) ;
@@ -124,7 +122,7 @@ fn get_solved_ids() -> Vec<u32> {
124122 for path in paths {
125123 let path = path. unwrap ( ) . path ( ) ;
126124 let s = path. to_str ( ) . unwrap ( ) ;
127- if s . chars ( ) . next ( ) . unwrap ( ) != 'n' {
125+ if !s . starts_with ( 'n' ) {
128126 continue ;
129127 }
130128 let id = & s[ 7 ..11 ] ;
0 commit comments