summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo8it <mo8it@proton.me>2025-08-22 00:01:03 +0200
committermo8it <mo8it@proton.me>2025-08-22 00:01:23 +0200
commit6ec2e194ae606ae4409a626ea0ac025229f6f4b1 (patch)
tree2064cf8626a245b7bc081429b45b9a5ed794d274
parent295ad2e4bd41147bf10028800a82247c2c0048a4 (diff)
Apply Clippy lints
-rw-r--r--src/embedded.rs8
-rw-r--r--src/exercise.rs22
-rw-r--r--src/list/state.rs17
3 files changed, 23 insertions, 24 deletions
diff --git a/src/embedded.rs b/src/embedded.rs
index 88c1fb0..61a5f58 100644
--- a/src/embedded.rs
+++ b/src/embedded.rs
@@ -20,10 +20,10 @@ struct ExerciseFiles {
}
fn create_dir_if_not_exists(path: &str) -> Result<()> {
- if let Err(e) = create_dir(path) {
- if e.kind() != io::ErrorKind::AlreadyExists {
- return Err(Error::from(e).context(format!("Failed to create the directory {path}")));
- }
+ if let Err(e) = create_dir(path)
+ && e.kind() != io::ErrorKind::AlreadyExists
+ {
+ return Err(Error::from(e).context(format!("Failed to create the directory {path}")));
}
Ok(())
diff --git a/src/exercise.rs b/src/exercise.rs
index 6f517be..a0596b5 100644
--- a/src/exercise.rs
+++ b/src/exercise.rs
@@ -48,17 +48,17 @@ fn run_bin(
let success = cmd_runner.run_debug_bin(bin_name, output.as_deref_mut())?;
- if let Some(output) = output {
- if !success {
- // This output is important to show the user that something went wrong.
- // Otherwise, calling something like `exit(1)` in an exercise without further output
- // leaves the user confused about why the exercise isn't done yet.
- write_ansi(output, SetAttribute(Attribute::Bold));
- write_ansi(output, SetForegroundColor(Color::Red));
- output.extend_from_slice(b"The exercise didn't run successfully (nonzero exit code)");
- write_ansi(output, ResetColor);
- output.push(b'\n');
- }
+ if let Some(output) = output
+ && !success
+ {
+ // This output is important to show the user that something went wrong.
+ // Otherwise, calling something like `exit(1)` in an exercise without further output
+ // leaves the user confused about why the exercise isn't done yet.
+ write_ansi(output, SetAttribute(Attribute::Bold));
+ write_ansi(output, SetForegroundColor(Color::Red));
+ output.extend_from_slice(b"The exercise didn't run successfully (nonzero exit code)");
+ write_ansi(output, ResetColor);
+ output.push(b'\n');
}
Ok(success)
diff --git a/src/list/state.rs b/src/list/state.rs
index 50d06be..4fd1301 100644
--- a/src/list/state.rs
+++ b/src/list/state.rs
@@ -118,8 +118,8 @@ impl<'a> ListState<'a> {
}
fn draw_exercise_name(&self, writer: &mut MaxLenWriter, exercise: &Exercise) -> io::Result<()> {
- if !self.search_query.is_empty() {
- if let Some((pre_highlight, highlight, post_highlight)) = exercise
+ if !self.search_query.is_empty()
+ && let Some((pre_highlight, highlight, post_highlight)) = exercise
.name
.find(&self.search_query)
.and_then(|ind| exercise.name.split_at_checked(ind))
@@ -127,13 +127,12 @@ impl<'a> ListState<'a> {
rest.split_at_checked(self.search_query.len())
.map(|x| (pre_highlight, x.0, x.1))
})
- {
- writer.write_str(pre_highlight)?;
- writer.stdout.queue(SetForegroundColor(Color::Magenta))?;
- writer.write_str(highlight)?;
- writer.stdout.queue(SetForegroundColor(Color::Reset))?;
- return writer.write_str(post_highlight);
- }
+ {
+ writer.write_str(pre_highlight)?;
+ writer.stdout.queue(SetForegroundColor(Color::Magenta))?;
+ writer.write_str(highlight)?;
+ writer.stdout.queue(SetForegroundColor(Color::Reset))?;
+ return writer.write_str(post_highlight);
}
writer.write_str(exercise.name)