Make code more concise and simpler to read

This commit is contained in:
Tobie Morgan Hitchcock 2022-04-01 00:40:16 +01:00
parent 7e2eae32c5
commit 7e51401ebb
2 changed files with 13 additions and 7 deletions

View file

@ -13,9 +13,9 @@ impl<'a> Document<'a> {
_txn: &Transaction, _txn: &Transaction,
stm: &Statement, stm: &Statement,
) -> Result<(), Error> { ) -> Result<(), Error> {
match self.id { // Check that we are altering a record
Some(_) => Ok(()), if self.id.is_none() {
None => match stm { return match stm {
Statement::Create(_) => Err(Error::CreateStatement { Statement::Create(_) => Err(Error::CreateStatement {
value: (*self.initial).clone(), value: (*self.initial).clone(),
}), }),
@ -32,7 +32,9 @@ impl<'a> Document<'a> {
value: (*self.initial).clone(), value: (*self.initial).clone(),
}), }),
_ => unreachable!(), _ => unreachable!(),
}, };
} }
// Carry on
Ok(())
} }
} }

View file

@ -13,9 +13,13 @@ impl<'a> Document<'a> {
_txn: &Transaction, _txn: &Transaction,
_stm: &Statement, _stm: &Statement,
) -> Result<(), Error> { ) -> Result<(), Error> {
match self.id.is_some() && self.current.is_none() { // Check if this record exists
true => Err(Error::Ignore), if self.id.is_some() {
false => Ok(()), if self.current.is_none() {
return Err(Error::Ignore);
}
} }
// Carry on
Ok(())
} }
} }