Skip to content

Commit

Permalink
change from basic if statement to matches
Browse files Browse the repository at this point in the history
  • Loading branch information
darkmmon committed Jun 20, 2023
1 parent e5a6241 commit 240ec4f
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions src/executor/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,11 @@ where
TryInsertResult::Empty
} else {
let temp = self.insert_struct.exec(db).await;
if temp.is_err()
&& temp.as_ref().expect_err("must be error by previous check")
== &DbErr::RecordNotInserted
{
return TryInsertResult::Conflicted;
if matches!(temp, Err(DbErr::RecordNotInserted)) {
TryInsertResult::Conflicted
} else {
TryInsertResult::Inserted(temp)
}
TryInsertResult::Inserted(temp)
}
}

Expand All @@ -78,13 +76,11 @@ where
TryInsertResult::Empty
} else {
let temp = self.insert_struct.exec_without_returning(db).await;
if temp.is_err()
&& temp.as_ref().expect_err("must be error by previous check")
== &DbErr::RecordNotInserted
{
return TryInsertResult::Conflicted;
if matches!(temp, Err(DbErr::RecordNotInserted)) {
TryInsertResult::Conflicted
} else {
TryInsertResult::Inserted(temp)
}
TryInsertResult::Inserted(temp)
}
}

Expand All @@ -102,13 +98,11 @@ where
TryInsertResult::Empty
} else {
let temp = self.insert_struct.exec_with_returning(db).await;
if temp.is_err()
&& temp.as_ref().expect_err("must be error by previous check")
== &DbErr::RecordNotInserted
{
return TryInsertResult::Conflicted;
if matches!(temp, Err(DbErr::RecordNotInserted)) {
TryInsertResult::Conflicted
} else {
TryInsertResult::Inserted(temp)
}
TryInsertResult::Inserted(temp)
}
}
}
Expand Down

0 comments on commit 240ec4f

Please sign in to comment.