Replace .unwrap() with ? operator

This commit is contained in:
Brandon Vandegrift 2023-09-12 08:06:49 -04:00
parent c2c607efac
commit ac8bbe9a83
4 changed files with 88 additions and 96 deletions

View file

@ -63,11 +63,11 @@ impl VeilidTableDB {
/// Read a key from a column in the TableDB immediately.
pub async fn load(&mut self, columnId: u32, key: String) -> APIResult<Option<String>> {
self.ensureOpen().await;
let key = unmarshall(key);
let key = unmarshall(key)?;
let table_db = self.getTableDB()?;
let out = table_db.load(columnId, &key).await?.unwrap();
let out = Some(marshall(&out));
let out = table_db.load(columnId, &key).await?;
let out = out.map(|out| marshall(&out));
APIResult::Ok(out)
}
@ -75,8 +75,8 @@ impl VeilidTableDB {
/// Performs a single transaction immediately.
pub async fn store(&mut self, columnId: u32, key: String, value: String) -> APIResult<()> {
self.ensureOpen().await;
let key = unmarshall(key);
let value = unmarshall(value);
let key = unmarshall(key)?;
let value = unmarshall(value)?;
let table_db = self.getTableDB()?;
table_db.store(columnId, &key, &value).await?;
@ -86,11 +86,11 @@ impl VeilidTableDB {
/// Delete key with from a column in the TableDB.
pub async fn delete(&mut self, columnId: u32, key: String) -> APIResult<Option<String>> {
self.ensureOpen().await;
let key = unmarshall(key);
let key = unmarshall(key)?;
let table_db = self.getTableDB()?;
let out = table_db.delete(columnId, &key).await?.unwrap();
let out = Some(marshall(&out));
let out = table_db.delete(columnId, &key).await?;
let out = out.map(|out| marshall(&out));
APIResult::Ok(out)
}
@ -161,15 +161,15 @@ impl VeilidTableDBTransaction {
/// Store a key with a value in a column in the TableDB.
/// Does not modify TableDB until `.commit()` is called.
pub fn store(&self, col: u32, key: String, value: String) -> APIResult<()> {
let key = unmarshall(key);
let value = unmarshall(value);
let key = unmarshall(key)?;
let value = unmarshall(value)?;
let transaction = self.getTransaction()?;
transaction.store(col, &key, &value)
}
/// Delete key with from a column in the TableDB
pub fn deleteKey(&self, col: u32, key: String) -> APIResult<()> {
let key = unmarshall(key);
let key = unmarshall(key)?;
let transaction = self.getTransaction()?;
transaction.delete(col, &key)
}