Skip to content

Commit

Permalink
Merge pull request #53 from dcSpark/egostkin/change-last-api
Browse files Browse the repository at this point in the history
Change indexed log map's .last return type
  • Loading branch information
gostkin authored Sep 22, 2023
2 parents 001c8ef + 2ee653d commit bc75e35
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions indexed-log-map/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,20 @@ impl<Key: Serialize + DeserializeOwned, Value: Serialize + DeserializeOwned>
}))
}

pub fn last(&self) -> Result<Option<Result<Value>>> {
Ok(self
pub fn last(&self) -> Result<Option<Value>> {
let last = self
.storage
.last()
.map_err(|err| anyhow!("can't get last element of the storage: {:?}", err))?
.map(|mmap| -> Result<Value> {
ciborium::de::from_reader(mmap.as_slice()).context("can't deserialize cbor rep")
}))
.map_err(|err| anyhow!("can't get last element of the storage: {:?}", err))?;
let value = match last {
None => None,
Some(mmap) => {
let value: Value = ciborium::de::from_reader(mmap.as_slice())
.context("can't deserialize cbor rep")?;
Some(value)
}
};
Ok(value)
}
}

Expand Down

0 comments on commit bc75e35

Please sign in to comment.