From 7e51401ebb1cefa1412170842fe576786d7a5681 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Fri, 1 Apr 2022 00:40:16 +0100 Subject: [PATCH] Make code more concise and simpler to read --- lib/src/doc/admit.rs | 10 ++++++---- lib/src/doc/empty.rs | 10 +++++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/src/doc/admit.rs b/lib/src/doc/admit.rs index 2959d2e5..6ea88dec 100644 --- a/lib/src/doc/admit.rs +++ b/lib/src/doc/admit.rs @@ -13,9 +13,9 @@ impl<'a> Document<'a> { _txn: &Transaction, stm: &Statement, ) -> Result<(), Error> { - match self.id { - Some(_) => Ok(()), - None => match stm { + // Check that we are altering a record + if self.id.is_none() { + return match stm { Statement::Create(_) => Err(Error::CreateStatement { value: (*self.initial).clone(), }), @@ -32,7 +32,9 @@ impl<'a> Document<'a> { value: (*self.initial).clone(), }), _ => unreachable!(), - }, + }; } + // Carry on + Ok(()) } } diff --git a/lib/src/doc/empty.rs b/lib/src/doc/empty.rs index 7af2b21a..561e26ae 100644 --- a/lib/src/doc/empty.rs +++ b/lib/src/doc/empty.rs @@ -13,9 +13,13 @@ impl<'a> Document<'a> { _txn: &Transaction, _stm: &Statement, ) -> Result<(), Error> { - match self.id.is_some() && self.current.is_none() { - true => Err(Error::Ignore), - false => Ok(()), + // Check if this record exists + if self.id.is_some() { + if self.current.is_none() { + return Err(Error::Ignore); + } } + // Carry on + Ok(()) } }