update errors handle

This commit is contained in:
yggverse 2024-11-22 15:51:03 +02:00
parent 48ad344adc
commit efa3bc48c3
9 changed files with 61 additions and 74 deletions

View file

@ -24,7 +24,7 @@ impl Memory {
/// * validate record with same key does not exist yet
pub fn add(&self, request: String, id: i64) -> Result<(), Error> {
match self.index.borrow_mut().insert(request, id) {
Some(_) => Err(Error::Overwrite), // @TODO prevent?
Some(key) => Err(Error::Overwrite(key)), // @TODO prevent?
None => Ok(()),
}
}

View file

@ -1,5 +1,5 @@
#[derive(Debug)]
pub enum Error {
NotFound,
Overwrite,
Overwrite(i64),
}