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,
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(())
}
}

View file

@ -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(())
}
}