Skip to content

Commit 8e0f7e5

Browse files
committed
Merge branch 'main' into which
2 parents 51b4c24 + 87ca05b commit 8e0f7e5

File tree

6 files changed

+29
-44
lines changed

6 files changed

+29
-44
lines changed

Cargo.lock

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ edition = "2021"
1212
clap = { version = "4.5.2", features = ["derive"] }
1313
console = "0.15.8"
1414
glob = "0.3.0"
15-
home = "0.5.9"
1615
indicatif = "0.17.8"
1716
notify-debouncer-mini = "0.4.1"
1817
regex = "1.10.3"

src/exercise.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub struct Exercise {
5858

5959
// An enum to track of the state of an Exercise.
6060
// An Exercise can be either Done or Pending
61-
#[derive(PartialEq, Debug)]
61+
#[derive(PartialEq, Eq, Debug)]
6262
pub enum State {
6363
// The state of the exercise once it's been completed
6464
Done,
@@ -67,7 +67,7 @@ pub enum State {
6767
}
6868

6969
// The context information of a pending exercise
70-
#[derive(PartialEq, Debug)]
70+
#[derive(PartialEq, Eq, Debug)]
7171
pub struct ContextLine {
7272
// The source code that is still pending completion
7373
pub line: String,

src/main.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -217,16 +217,13 @@ fn main() {
217217
println!("Failed to write rust-project.json to disk for rust-analyzer");
218218
} else {
219219
println!("Successfully generated rust-project.json");
220-
println!("rust-analyzer will now parse exercises, restart your language server or editor")
220+
println!("rust-analyzer will now parse exercises, restart your language server or editor");
221221
}
222222
}
223223

224224
Subcommands::Watch { success_hints } => match watch(&exercises, verbose, success_hints) {
225225
Err(e) => {
226-
println!(
227-
"Error: Could not watch your progress. Error message was {:?}.",
228-
e
229-
);
226+
println!("Error: Could not watch your progress. Error message was {e:?}.");
230227
println!("Most likely you've run out of disk space or your 'inotify limit' has been reached.");
231228
std::process::exit(1);
232229
}
@@ -280,7 +277,7 @@ fn spawn_watch_shell(
280277
if parts.is_empty() {
281278
println!("no command provided");
282279
} else if let Err(e) = Command::new(parts[0]).args(&parts[1..]).status() {
283-
println!("failed to execute command `{}`: {}", cmd, e);
280+
println!("failed to execute command `{cmd}`: {e}");
284281
}
285282
} else {
286283
println!("unknown command: {input}");
@@ -292,7 +289,7 @@ fn spawn_watch_shell(
292289
}
293290

294291
fn find_exercise<'a>(name: &str, exercises: &'a [Exercise]) -> &'a Exercise {
295-
if name.eq("next") {
292+
if name == "next" {
296293
exercises
297294
.iter()
298295
.find(|e| !e.looks_done())
@@ -338,15 +335,14 @@ fn watch(
338335

339336
clear_screen();
340337

341-
let to_owned_hint = |t: &Exercise| t.hint.to_owned();
342338
let failed_exercise_hint = match verify(
343339
exercises.iter(),
344340
(0, exercises.len()),
345341
verbose,
346342
success_hints,
347343
) {
348344
Ok(_) => return Ok(WatchStatus::Finished),
349-
Err(exercise) => Arc::new(Mutex::new(Some(to_owned_hint(exercise)))),
345+
Err(exercise) => Arc::new(Mutex::new(Some(exercise.hint.clone()))),
350346
};
351347
spawn_watch_shell(&failed_exercise_hint, Arc::clone(&should_quit));
352348
loop {
@@ -383,7 +379,7 @@ fn watch(
383379
Err(exercise) => {
384380
let mut failed_exercise_hint =
385381
failed_exercise_hint.lock().unwrap();
386-
*failed_exercise_hint = Some(to_owned_hint(exercise));
382+
*failed_exercise_hint = Some(exercise.hint.clone());
387383
}
388384
}
389385
}
@@ -403,7 +399,7 @@ fn watch(
403399
}
404400
}
405401

406-
const DEFAULT_OUT: &str = r#"Thanks for installing Rustlings!
402+
const DEFAULT_OUT: &str = "Thanks for installing Rustlings!
407403
408404
Is this your first time? Don't worry, Rustlings was made for beginners! We are
409405
going to teach you a lot of things about Rust, but before we can get
@@ -429,7 +425,7 @@ started, here's a couple of notes about how Rustlings operates:
429425
autocompletion, run the command `rustlings lsp`.
430426
431427
Got all that? Great! To get started, run `rustlings watch` in order to get the first
432-
exercise. Make sure to have your editor open!"#;
428+
exercise. Make sure to have your editor open!";
433429

434430
const FENISH_LINE: &str = "+----------------------------------------------------+
435431
| You made it to the Fe-nish line! |

src/run.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ pub fn run(exercise: &Exercise, verbose: bool) -> Result<(), ()> {
2121
// Resets the exercise by stashing the changes.
2222
pub fn reset(exercise: &Exercise) -> Result<(), ()> {
2323
let command = Command::new("git")
24-
.args(["stash", "--"])
24+
.arg("stash")
25+
.arg("--")
2526
.arg(&exercise.path)
2627
.spawn();
2728

src/verify.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub fn verify<'a>(
2424
.progress_chars("#>-"),
2525
);
2626
bar.set_position(num_done as u64);
27-
bar.set_message(format!("({:.1} %)", percentage));
27+
bar.set_message(format!("({percentage:.1} %)"));
2828

2929
for exercise in exercises {
3030
let compile_result = match exercise.mode {
@@ -37,7 +37,7 @@ pub fn verify<'a>(
3737
}
3838
percentage += 100.0 / total as f32;
3939
bar.inc(1);
40-
bar.set_message(format!("({:.1} %)", percentage));
40+
bar.set_message(format!("({percentage:.1} %)"));
4141
if bar.position() == total as u64 {
4242
println!(
4343
"Progress: You completed {} / {} exercises ({:.1} %).",
@@ -51,6 +51,7 @@ pub fn verify<'a>(
5151
Ok(())
5252
}
5353

54+
#[derive(PartialEq, Eq)]
5455
enum RunMode {
5556
Interactive,
5657
NonInteractive,
@@ -124,7 +125,7 @@ fn compile_and_test(
124125
if verbose {
125126
println!("{}", output.stdout);
126127
}
127-
if let RunMode::Interactive = run_mode {
128+
if run_mode == RunMode::Interactive {
128129
Ok(prompt_for_completion(exercise, None, success_hints))
129130
} else {
130131
Ok(true)
@@ -191,27 +192,25 @@ fn prompt_for_completion(
191192
Mode::Test => "The code is compiling, and the tests pass!",
192193
Mode::Clippy => clippy_success_msg,
193194
};
194-
println!();
195+
195196
if no_emoji {
196-
println!("~*~ {success_msg} ~*~")
197+
println!("\n~*~ {success_msg} ~*~\n");
197198
} else {
198-
println!("🎉 🎉 {success_msg} 🎉 🎉")
199+
println!("\n🎉 🎉 {success_msg} 🎉 🎉\n");
199200
}
200-
println!();
201201

202202
if let Some(output) = prompt_output {
203-
println!("Output:");
204-
println!("{}", separator());
205-
println!("{output}");
206-
println!("{}", separator());
207-
println!();
203+
println!(
204+
"Output:\n{separator}\n{output}\n{separator}\n",
205+
separator = separator(),
206+
);
208207
}
209208
if success_hints {
210-
println!("Hints:");
211-
println!("{}", separator());
212-
println!("{}", exercise.hint);
213-
println!("{}", separator());
214-
println!();
209+
println!(
210+
"Hints:\n{separator}\n{}\n{separator}\n",
211+
exercise.hint,
212+
separator = separator(),
213+
);
215214
}
216215

217216
println!("You can keep working on this exercise,");
@@ -231,7 +230,7 @@ fn prompt_for_completion(
231230
"{:>2} {} {}",
232231
style(context_line.number).blue().bold(),
233232
style("|").blue(),
234-
formatted_line
233+
formatted_line,
235234
);
236235
}
237236

0 commit comments

Comments
 (0)