Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ readme = "README.md"
edition = "2018"

[dependencies]
failure = "0.1.6"
anyhow = "1.0.26"
random-access-storage = "3.0.0"

[dev-dependencies]
Expand Down
24 changes: 13 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#![cfg_attr(feature = "nightly", doc(include = "../README.md"))]
#![cfg_attr(test, deny(warnings))]

use failure::{ensure, Error};
use anyhow::anyhow;
use random_access_storage::RandomAccess;
use std::cmp;
use std::io;
Expand Down Expand Up @@ -53,7 +53,7 @@ impl RandomAccessMemory {
}

impl RandomAccess for RandomAccessMemory {
type Error = Error;
type Error = Box<dyn std::error::Error + Send + Sync>;

fn write(&mut self, offset: u64, data: &[u8]) -> Result<(), Self::Error> {
let new_len = offset + data.len() as u64;
Expand Down Expand Up @@ -106,15 +106,17 @@ impl RandomAccess for RandomAccessMemory {
}

fn read(&mut self, offset: u64, length: u64) -> Result<Vec<u8>, Self::Error> {
ensure!(
(offset + length) <= self.length,
format!(
"Read bounds exceeded. {} < {}..{}",
self.length,
offset,
offset + length
)
);
if (offset + length) > self.length {
return Err(
anyhow!(
"Read bounds exceeded. {} < {}..{}",
self.length,
offset,
offset + length
)
.into(),
);
};

let mut page_num = (offset / self.page_size as u64) as usize;
let mut page_cursor =
Expand Down