@@ -10,7 +10,7 @@ use std::ffi::OsStr;
10
10
use std:: fs;
11
11
use std:: io:: { self , prelude:: * } ;
12
12
use std:: path:: Path ;
13
- use std:: process:: { Command , Stdio } ;
13
+ use std:: process:: Command ;
14
14
use std:: sync:: atomic:: { AtomicBool , Ordering } ;
15
15
use std:: sync:: mpsc:: { channel, RecvTimeoutError } ;
16
16
use std:: sync:: { Arc , Mutex } ;
@@ -91,7 +91,7 @@ fn main() {
91
91
println ! ( "\n {WELCOME}\n " ) ;
92
92
}
93
93
94
- if ! rustc_exists ( ) {
94
+ if which :: which ( "rustc" ) . is_err ( ) {
95
95
println ! ( "We cannot find `rustc`." ) ;
96
96
println ! ( "Try running `rustc --version` to diagnose your problem." ) ;
97
97
println ! ( "For instructions on how to install Rust, check the README." ) ;
@@ -218,16 +218,13 @@ fn main() {
218
218
println ! ( "Failed to write rust-project.json to disk for rust-analyzer" ) ;
219
219
} else {
220
220
println ! ( "Successfully generated rust-project.json" ) ;
221
- println ! ( "rust-analyzer will now parse exercises, restart your language server or editor" )
221
+ println ! ( "rust-analyzer will now parse exercises, restart your language server or editor" ) ;
222
222
}
223
223
}
224
224
225
225
Subcommands :: Watch { success_hints } => match watch ( & exercises, verbose, success_hints) {
226
226
Err ( e) => {
227
- println ! (
228
- "Error: Could not watch your progress. Error message was {:?}." ,
229
- e
230
- ) ;
227
+ println ! ( "Error: Could not watch your progress. Error message was {e:?}." ) ;
231
228
println ! ( "Most likely you've run out of disk space or your 'inotify limit' has been reached." ) ;
232
229
std:: process:: exit ( 1 ) ;
233
230
}
@@ -281,7 +278,7 @@ fn spawn_watch_shell(
281
278
if parts. is_empty ( ) {
282
279
println ! ( "no command provided" ) ;
283
280
} else if let Err ( e) = Command :: new ( parts[ 0 ] ) . args ( & parts[ 1 ..] ) . status ( ) {
284
- println ! ( "failed to execute command `{}`: {}" , cmd , e ) ;
281
+ println ! ( "failed to execute command `{cmd }`: {e}" ) ;
285
282
}
286
283
} else {
287
284
println ! ( "unknown command: {input}" ) ;
@@ -293,7 +290,7 @@ fn spawn_watch_shell(
293
290
}
294
291
295
292
fn find_exercise < ' a > ( name : & str , exercises : & ' a [ Exercise ] ) -> & ' a Exercise {
296
- if name. eq ( "next" ) {
293
+ if name == "next" {
297
294
exercises
298
295
. iter ( )
299
296
. find ( |e| !e. looks_done ( ) )
@@ -339,15 +336,14 @@ fn watch(
339
336
340
337
clear_screen ( ) ;
341
338
342
- let to_owned_hint = |t : & Exercise | t. hint . to_owned ( ) ;
343
339
let failed_exercise_hint = match verify (
344
340
exercises. iter ( ) ,
345
341
( 0 , exercises. len ( ) ) ,
346
342
verbose,
347
343
success_hints,
348
344
) {
349
345
Ok ( _) => return Ok ( WatchStatus :: Finished ) ,
350
- Err ( exercise) => Arc :: new ( Mutex :: new ( Some ( to_owned_hint ( exercise) ) ) ) ,
346
+ Err ( exercise) => Arc :: new ( Mutex :: new ( Some ( exercise. hint . clone ( ) ) ) ) ,
351
347
} ;
352
348
spawn_watch_shell ( & failed_exercise_hint, Arc :: clone ( & should_quit) ) ;
353
349
loop {
@@ -384,7 +380,7 @@ fn watch(
384
380
Err ( exercise) => {
385
381
let mut failed_exercise_hint =
386
382
failed_exercise_hint. lock ( ) . unwrap ( ) ;
387
- * failed_exercise_hint = Some ( to_owned_hint ( exercise) ) ;
383
+ * failed_exercise_hint = Some ( exercise. hint . clone ( ) ) ;
388
384
}
389
385
}
390
386
}
@@ -404,19 +400,7 @@ fn watch(
404
400
}
405
401
}
406
402
407
- fn rustc_exists ( ) -> bool {
408
- Command :: new ( "rustc" )
409
- . args ( [ "--version" ] )
410
- . stdout ( Stdio :: null ( ) )
411
- . stderr ( Stdio :: null ( ) )
412
- . stdin ( Stdio :: null ( ) )
413
- . spawn ( )
414
- . and_then ( |mut child| child. wait ( ) )
415
- . map ( |status| status. success ( ) )
416
- . unwrap_or ( false )
417
- }
418
-
419
- const DEFAULT_OUT : & str = r#"Thanks for installing Rustlings!
403
+ const DEFAULT_OUT : & str = "Thanks for installing Rustlings!
420
404
421
405
Is this your first time? Don't worry, Rustlings was made for beginners! We are
422
406
going to teach you a lot of things about Rust, but before we can get
@@ -442,7 +426,7 @@ started, here's a couple of notes about how Rustlings operates:
442
426
autocompletion, run the command `rustlings lsp`.
443
427
444
428
Got all that? Great! To get started, run `rustlings watch` in order to get the first
445
- exercise. Make sure to have your editor open!"# ;
429
+ exercise. Make sure to have your editor open!" ;
446
430
447
431
const FENISH_LINE : & str = "+----------------------------------------------------+
448
432
| You made it to the Fe-nish line! |
0 commit comments