From 240ec4f5309875a969081a667ff1e73888952ae2 Mon Sep 17 00:00:00 2001 From: Yiu Tin Cheung Ivan Date: Tue, 20 Jun 2023 18:53:30 +0800 Subject: [PATCH] change from basic if statement to matches --- src/executor/insert.rs | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) 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) } } }