@@ -10,7 +10,7 @@ use std::ffi::OsStr;
1010use std:: fs;
1111use std:: io:: { self , prelude:: * } ;
1212use std:: path:: Path ;
13- use std:: process:: { Command , Stdio } ;
13+ use std:: process:: Command ;
1414use std:: sync:: atomic:: { AtomicBool , Ordering } ;
1515use std:: sync:: mpsc:: { channel, RecvTimeoutError } ;
1616use std:: sync:: { Arc , Mutex } ;
@@ -91,7 +91,7 @@ fn main() {
9191 println ! ( "\n {WELCOME}\n " ) ;
9292 }
9393
94- if ! rustc_exists ( ) {
94+ if which :: which ( "rustc" ) . is_err ( ) {
9595 println ! ( "We cannot find `rustc`." ) ;
9696 println ! ( "Try running `rustc --version` to diagnose your problem." ) ;
9797 println ! ( "For instructions on how to install Rust, check the README." ) ;
@@ -218,16 +218,13 @@ fn main() {
218218 println ! ( "Failed to write rust-project.json to disk for rust-analyzer" ) ;
219219 } else {
220220 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" ) ;
222222 }
223223 }
224224
225225 Subcommands :: Watch { success_hints } => match watch ( & exercises, verbose, success_hints) {
226226 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:?}." ) ;
231228 println ! ( "Most likely you've run out of disk space or your 'inotify limit' has been reached." ) ;
232229 std:: process:: exit ( 1 ) ;
233230 }
@@ -281,7 +278,7 @@ fn spawn_watch_shell(
281278 if parts. is_empty ( ) {
282279 println ! ( "no command provided" ) ;
283280 } 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}" ) ;
285282 }
286283 } else {
287284 println ! ( "unknown command: {input}" ) ;
@@ -293,7 +290,7 @@ fn spawn_watch_shell(
293290}
294291
295292fn find_exercise < ' a > ( name : & str , exercises : & ' a [ Exercise ] ) -> & ' a Exercise {
296- if name. eq ( "next" ) {
293+ if name == "next" {
297294 exercises
298295 . iter ( )
299296 . find ( |e| !e. looks_done ( ) )
@@ -339,15 +336,14 @@ fn watch(
339336
340337 clear_screen ( ) ;
341338
342- let to_owned_hint = |t : & Exercise | t. hint . to_owned ( ) ;
343339 let failed_exercise_hint = match verify (
344340 exercises. iter ( ) ,
345341 ( 0 , exercises. len ( ) ) ,
346342 verbose,
347343 success_hints,
348344 ) {
349345 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 ( ) ) ) ) ,
351347 } ;
352348 spawn_watch_shell ( & failed_exercise_hint, Arc :: clone ( & should_quit) ) ;
353349 loop {
@@ -384,7 +380,7 @@ fn watch(
384380 Err ( exercise) => {
385381 let mut failed_exercise_hint =
386382 failed_exercise_hint. lock ( ) . unwrap ( ) ;
387- * failed_exercise_hint = Some ( to_owned_hint ( exercise) ) ;
383+ * failed_exercise_hint = Some ( exercise. hint . clone ( ) ) ;
388384 }
389385 }
390386 }
@@ -404,19 +400,7 @@ fn watch(
404400 }
405401}
406402
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!
420404
421405Is this your first time? Don't worry, Rustlings was made for beginners! We are
422406going 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:
442426 autocompletion, run the command `rustlings lsp`.
443427
444428Got 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!" ;
446430
447431const FENISH_LINE : & str = "+----------------------------------------------------+
448432| You made it to the Fe-nish line! |
0 commit comments