1
0
mirror of https://github.com/rust-lang/rustlings.git synced 2025-07-03 00:46:57 +02:00

fix(cli): remove unnecessary borrows (#829)

* Update dependencies

* Format better and remove unnecessary borrows
This commit is contained in:
Ben Armstead
2021-08-24 12:06:30 +00:00
committed by GitHub
parent ec527824b4
commit 1cd9328a58
4 changed files with 68 additions and 66 deletions

View File

@ -162,7 +162,7 @@ path = "{}.rs""#,
if cmd.status.success() {
Ok(CompiledExercise {
exercise: &self,
exercise: self,
_handle: FileHandle,
})
} else {

View File

@ -203,7 +203,7 @@ fn main() {
Subcommands::Run(subargs) => {
let exercise = find_exercise(&subargs.name, &exercises);
run(&exercise, verbose).unwrap_or_else(|_| std::process::exit(1));
run(exercise, verbose).unwrap_or_else(|_| std::process::exit(1));
}
Subcommands::Hint(subargs) => {

View File

@ -14,9 +14,9 @@ pub fn verify<'a>(
) -> Result<(), &'a Exercise> {
for exercise in start_at {
let compile_result = match exercise.mode {
Mode::Test => compile_and_test(&exercise, RunMode::Interactive, verbose),
Mode::Compile => compile_and_run_interactively(&exercise),
Mode::Clippy => compile_only(&exercise),
Mode::Test => compile_and_test(exercise, RunMode::Interactive, verbose),
Mode::Compile => compile_and_run_interactively(exercise),
Mode::Clippy => compile_only(exercise),
};
if !compile_result.unwrap_or(false) {
return Err(exercise);
@ -42,11 +42,11 @@ fn compile_only(exercise: &Exercise) -> Result<bool, ()> {
progress_bar.set_message(format!("Compiling {}...", exercise).as_str());
progress_bar.enable_steady_tick(100);
let _ = compile(&exercise, &progress_bar)?;
let _ = compile(exercise, &progress_bar)?;
progress_bar.finish_and_clear();
success!("Successfully compiled {}!", exercise);
Ok(prompt_for_completion(&exercise, None))
Ok(prompt_for_completion(exercise, None))
}
// Compile the given Exercise and run the resulting binary in an interactive mode
@ -55,7 +55,7 @@ fn compile_and_run_interactively(exercise: &Exercise) -> Result<bool, ()> {
progress_bar.set_message(format!("Compiling {}...", exercise).as_str());
progress_bar.enable_steady_tick(100);
let compilation = compile(&exercise, &progress_bar)?;
let compilation = compile(exercise, &progress_bar)?;
progress_bar.set_message(format!("Running {}...", exercise).as_str());
let result = compilation.run();
@ -73,7 +73,7 @@ fn compile_and_run_interactively(exercise: &Exercise) -> Result<bool, ()> {
success!("Successfully ran {}!", exercise);
Ok(prompt_for_completion(&exercise, Some(output.stdout)))
Ok(prompt_for_completion(exercise, Some(output.stdout)))
}
// Compile the given Exercise as a test harness and display
@ -94,7 +94,7 @@ fn compile_and_test(exercise: &Exercise, run_mode: RunMode, verbose: bool) -> Re
}
success!("Successfully tested {}", &exercise);
if let RunMode::Interactive = run_mode {
Ok(prompt_for_completion(&exercise, None))
Ok(prompt_for_completion(exercise, None))
} else {
Ok(true)
}