diff --git a/src/executor/insert.rs b/src/executor/insert.rs index b48b063b0a..1348f8fbaa 100644 --- a/src/executor/insert.rs +++ b/src/executor/insert.rs @@ -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) } } @@ -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) } } @@ -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) } } }