Skip to content

Commit

Permalink
Make ObjRef Debug (#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkuris authored Jan 8, 2024
1 parent 5c9ced2 commit aa39d2f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion firewood/src/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl<S: ShaleStore<Node> + Send + Sync, T> Merkle<S, T> {
.map(|node| node.as_ptr())
}

pub fn get_store(&self) -> &dyn ShaleStore<Node> {
pub fn get_store(&self) -> &S {
self.store.as_ref()
}

Expand Down
4 changes: 3 additions & 1 deletion firewood/src/shale/compact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,9 @@ impl From<Box<CompactSpace<Node, StoreRevMut>>> for CompactSpace<Node, StoreRevS
}
}

impl<T: Storable + 'static, M: CachedStore + Send + Sync> ShaleStore<T> for CompactSpace<T, M> {
impl<T: Storable + Debug + 'static + PartialEq, M: CachedStore + Send + Sync> ShaleStore<T>
for CompactSpace<T, M>
{
fn put_item(&self, item: T, extra: u64) -> Result<ObjRef<'_, T>, ShaleError> {
let size = item.serialized_len() + extra;
#[allow(clippy::unwrap_used)]
Expand Down
7 changes: 4 additions & 3 deletions firewood/src/shale/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,13 @@ impl<T: Storable> Deref for Obj<T> {
}

/// User handle that offers read & write access to the stored [ShaleStore] item.
#[derive(Debug)]
pub struct ObjRef<'a, T: Storable> {
inner: Option<Obj<T>>,
cache: &'a ObjCache<T>,
}

impl<'a, T: Storable> ObjRef<'a, T> {
impl<'a, T: Storable + Debug> ObjRef<'a, T> {
const fn new(inner: Option<Obj<T>>, cache: &'a ObjCache<T>) -> Self {
Self { inner, cache }
}
Expand All @@ -191,7 +192,7 @@ impl<'a, T: Storable> ObjRef<'a, T> {
}
}

impl<'a, T: Storable> Deref for ObjRef<'a, T> {
impl<'a, T: Storable + Debug> Deref for ObjRef<'a, T> {
type Target = Obj<T>;
fn deref(&self) -> &Obj<T> {
// TODO: Something is seriously wrong here but I'm not quite sure about the best approach for the fix
Expand Down Expand Up @@ -219,7 +220,7 @@ impl<'a, T: Storable> Drop for ObjRef<'a, T> {

/// A persistent item storage backed by linear logical space. New items can be created and old
/// items could be retrieved or dropped.
pub trait ShaleStore<T: Storable> {
pub trait ShaleStore<T: Storable + Debug> {
/// Dereference [DiskAddress] to a unique handle that allows direct access to the item in memory.
fn get_item(&'_ self, ptr: DiskAddress) -> Result<ObjRef<'_, T>, ShaleError>;
/// Allocate a new item.
Expand Down

0 comments on commit aa39d2f

Please sign in to comment.