@@ -34,7 +34,7 @@ fn main() {
34
34
_ => {
35
35
id = id_arg
36
36
. parse :: < u32 > ( )
37
- . expect ( & format ! ( "not a number: {}" , id_arg) ) ;
37
+ . unwrap_or_else ( |_| panic ! ( "not a number: {}" , id_arg) ) ;
38
38
if solved_ids. contains ( & id) {
39
39
println ! (
40
40
"The problem you chose is invalid (the problem may have been solved \
@@ -45,16 +45,14 @@ fn main() {
45
45
}
46
46
}
47
47
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" ) ;
58
56
if code. is_none ( ) {
59
57
println ! ( "Problem {} has no rust version." , & id) ;
60
58
solved_ids. push ( problem. question_id ) ;
@@ -100,7 +98,7 @@ fn main() {
100
98
}
101
99
}
102
100
103
- fn generate_random_id ( except_ids : & Vec < u32 > ) -> u32 {
101
+ fn generate_random_id ( except_ids : & [ u32 ] ) -> u32 {
104
102
use rand:: Rng ;
105
103
use std:: fs;
106
104
let mut rng = rand:: thread_rng ( ) ;
@@ -124,7 +122,7 @@ fn get_solved_ids() -> Vec<u32> {
124
122
for path in paths {
125
123
let path = path. unwrap ( ) . path ( ) ;
126
124
let s = path. to_str ( ) . unwrap ( ) ;
127
- if s . chars ( ) . next ( ) . unwrap ( ) != 'n' {
125
+ if !s . starts_with ( 'n' ) {
128
126
continue ;
129
127
}
130
128
let id = & s[ 7 ..11 ] ;
0 commit comments