Skip to content

Commit

Permalink
Fix new clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
epilys committed Aug 13, 2024
1 parent 346527c commit 3366e3b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 22 deletions.
12 changes: 2 additions & 10 deletions mailpot-cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,11 +434,7 @@ pub fn list(db: &mut Connection, list_id: &str, cmd: ListCommand, quiet: bool) -
for e in entries {
println!(
"{}{}<{}>",
if let Some(n) = e.display_name() {
n
} else {
""
},
e.display_name().unwrap_or_default(),
if e.display_name().is_none() { "" } else { " " },
e.email()
);
Expand All @@ -449,11 +445,7 @@ pub fn list(db: &mut Connection, list_id: &str, cmd: ListCommand, quiet: bool) -
for e in entries {
println!(
"{}{}<{}>",
if let Some(n) = e.display_name() {
n
} else {
""
},
e.display_name().unwrap_or_default(),
if e.display_name().is_none() { "" } else { " " },
e.email()
);
Expand Down
17 changes: 9 additions & 8 deletions mailpot/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ impl Connection {
stdin
.write_all(Self::SCHEMA.as_bytes())
.expect("failed to write to stdin");
#[allow(clippy::const_is_empty)]
if !Self::MIGRATIONS.is_empty() {
stdin
.write_all(b"\nPRAGMA user_version = ")
Expand Down Expand Up @@ -962,11 +963,11 @@ pub mod transaction {

impl Transaction<'_> {
/// Commit and consume transaction.
pub fn commit(mut self) -> Result<()> {
pub fn commit(self) -> Result<()> {
self.commit_()
}

fn commit_(&mut self) -> Result<()> {
fn commit_(&self) -> Result<()> {
self.conn.connection.execute_batch("COMMIT")?;
Ok(())
}
Expand All @@ -980,11 +981,11 @@ pub mod transaction {

/// A convenience method which consumes and rolls back a transaction.
#[inline]
pub fn rollback(mut self) -> Result<()> {
pub fn rollback(self) -> Result<()> {
self.rollback_()
}

fn rollback_(&mut self) -> Result<()> {
fn rollback_(&self) -> Result<()> {
self.conn.connection.execute_batch("ROLLBACK")?;
Ok(())
}
Expand All @@ -995,12 +996,12 @@ pub mod transaction {
/// Functionally equivalent to the `Drop` implementation, but allows
/// callers to see any errors that occur.
#[inline]
pub fn finish(mut self) -> Result<()> {
pub fn finish(self) -> Result<()> {
self.finish_()
}

#[inline]
fn finish_(&mut self) -> Result<()> {
fn finish_(&self) -> Result<()> {
if self.conn.connection.is_autocommit() {
return Ok(());
}
Expand Down Expand Up @@ -1106,11 +1107,11 @@ pub mod transaction {

/// A convenience method which consumes and rolls back a savepoint.
#[inline]
pub fn rollback(mut self) -> Result<()> {
pub fn rollback(self) -> Result<()> {
self.rollback_()
}

fn rollback_(&mut self) -> Result<()> {
fn rollback_(&self) -> Result<()> {
if !self.committed {
match self.name {
Ok(ref n) => self
Expand Down
8 changes: 4 additions & 4 deletions mailpot/tests/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ fn test_migration_gen() {
.write(true)
.create(true)
.truncate(true)
.open(&in_path.join(&format!("{num:03}.sql")))
.open(in_path.join(&format!("{num:03}.sql")))
.unwrap();
redo_file.write_all(redo.as_bytes()).unwrap();
redo_file.flush().unwrap();
Expand All @@ -177,7 +177,7 @@ fn test_migration_gen() {
.write(true)
.create(true)
.truncate(true)
.open(&in_path.join(&format!("{num:03}.undo.sql")))
.open(in_path.join(&format!("{num:03}.undo.sql")))
.unwrap();
undo_file.write_all(undo.as_bytes()).unwrap();
undo_file.flush().unwrap();
Expand All @@ -202,7 +202,7 @@ fn test_migration_gen_panic() {
.write(true)
.create(true)
.truncate(true)
.open(&in_path.join(&format!("{num:03}.sql")))
.open(in_path.join(&format!("{num:03}.sql")))
.unwrap();
redo_file.write_all(redo.as_bytes()).unwrap();
redo_file.flush().unwrap();
Expand All @@ -211,7 +211,7 @@ fn test_migration_gen_panic() {
.write(true)
.create(true)
.truncate(true)
.open(&in_path.join(&format!("{num:03}.undo.sql")))
.open(in_path.join(&format!("{num:03}.undo.sql")))
.unwrap();
undo_file.write_all(undo.as_bytes()).unwrap();
undo_file.flush().unwrap();
Expand Down

0 comments on commit 3366e3b

Please sign in to comment.