Skip to content

Commit

Permalink
style
Browse files Browse the repository at this point in the history
  • Loading branch information
uint committed Apr 7, 2024
1 parent e80671b commit e5bed8b
Showing 1 changed file with 46 additions and 46 deletions.
92 changes: 46 additions & 46 deletions crates/storey/src/containers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,52 @@ pub trait Storable {
#[derive(Debug, PartialEq)]
pub struct KeyDecodeError;

#[derive(Debug, PartialEq)]
pub enum KVDecodeError<V> {
Key,
Value(V),
}

pub trait IterableAccessor {
type StorableT: Storable;
type StorageT: IterableStorage;

fn storage(&self) -> &Self::StorageT;

fn pairs<'s>(
&'s self,
start: Option<&[u8]>,
end: Option<&[u8]>,
) -> StorableIter<'s, Self::StorableT, Self::StorageT> {
StorableIter {
inner: self.storage().pairs(start, end),
phantom: PhantomData,
}
}

fn keys<'s>(
&'s self,
start: Option<&[u8]>,
end: Option<&[u8]>,
) -> StorableKeys<'s, Self::StorableT, Self::StorageT> {
StorableKeys {
inner: self.storage().keys(start, end),
phantom: PhantomData,
}
}

fn values<'s>(
&'s self,
start: Option<&[u8]>,
end: Option<&[u8]>,
) -> StorableValues<'s, Self::StorableT, Self::StorageT> {
StorableValues {
inner: self.storage().values(start, end),
phantom: PhantomData,
}
}
}

pub struct StorableIter<'i, S, B>
where
S: Storable,
Expand Down Expand Up @@ -94,49 +140,3 @@ where
self.inner.next().map(|v| S::decode_value(&v))
}
}

#[derive(Debug, PartialEq)]
pub enum KVDecodeError<V> {
Key,
Value(V),
}

pub trait IterableAccessor {
type StorableT: Storable;
type StorageT: IterableStorage;

fn storage(&self) -> &Self::StorageT;

fn pairs<'s>(
&'s self,
start: Option<&[u8]>,
end: Option<&[u8]>,
) -> StorableIter<'s, Self::StorableT, Self::StorageT> {
StorableIter {
inner: self.storage().pairs(start, end),
phantom: PhantomData,
}
}

fn keys<'s>(
&'s self,
start: Option<&[u8]>,
end: Option<&[u8]>,
) -> StorableKeys<'s, Self::StorableT, Self::StorageT> {
StorableKeys {
inner: self.storage().keys(start, end),
phantom: PhantomData,
}
}

fn values<'s>(
&'s self,
start: Option<&[u8]>,
end: Option<&[u8]>,
) -> StorableValues<'s, Self::StorableT, Self::StorageT> {
StorableValues {
inner: self.storage().values(start, end),
phantom: PhantomData,
}
}
}

0 comments on commit e5bed8b

Please sign in to comment.