chore(db): comment for cursor, cleanup unneeded fn (#131)

This commit is contained in:
rakita
2022-10-25 10:34:30 +02:00
committed by GitHub
parent 2a8189d7c9
commit 1fe0affa4b
2 changed files with 15 additions and 11 deletions

View File

@ -126,6 +126,7 @@ impl<'tx, T: Table> DbCursorRW<'tx, T> for Cursor<'tx, RW, T> {
/// Database operation that will update an existing row if a specified value already
/// exists in a table, and insert a new row if the specified value doesn't already exist
fn upsert(&mut self, key: T::Key, value: T::Value) -> Result<(), Error> {
// Default `WriteFlags` is UPSERT
self.inner
.put(key.encode().as_ref(), value.encode().as_ref(), WriteFlags::UPSERT)
.map_err(|e| Error::Internal(e.into()))

View File

@ -154,11 +154,6 @@ pub trait DbCursorRO<'tx, T: Table> {
/// Returns the current `(key, value)` pair of the cursor.
fn current(&mut self) -> PairResult<T>;
/// Inner
fn inner(&'tx mut self) -> &'tx mut Self {
self
}
/// Returns an iterator starting at a key greater or equal than `start_key`.
fn walk<'cursor>(
&'cursor mut self,
@ -212,16 +207,20 @@ pub trait DbDupCursorRW<'tx, T: DupSort> {
}
/// Provides an iterator to `Cursor` when handling `Table`.
pub struct Walker<'cursor, 'tx, T: Table, CURSOR: DbCursorRO<'tx, T> + Sized> {
///
/// Reason why we have two lifetimes is to distinguish between `'cursor` lifetime
/// and inherited `'tx` lifetime. If there is only one, rust would short circle
/// the Cursor lifetime and it wouldn't be possible to use Walker.
pub struct Walker<'cursor, 'tx, T: Table, CURSOR: DbCursorRO<'tx, T>> {
/// Cursor to be used to walk through the table.
pub cursor: &'cursor mut CURSOR,
/// `(key, value)` where to start the walk.
pub start: IterPairResult<T>,
/// Phantom data for 'tx.
/// Phantom data for 'tx. As it is only used for `DbCursorRO`.
pub _tx_phantom: PhantomData<&'tx T>,
}
impl<'cursor, 'tx, T: Table, CURSOR: DbCursorRO<'tx, T> + Sized> std::iter::Iterator
impl<'cursor, 'tx, T: Table, CURSOR: DbCursorRO<'tx, T>> std::iter::Iterator
for Walker<'cursor, 'tx, T, CURSOR>
{
type Item = Result<(T::Key, T::Value), Error>;
@ -236,16 +235,20 @@ impl<'cursor, 'tx, T: Table, CURSOR: DbCursorRO<'tx, T> + Sized> std::iter::Iter
}
/// Provides an iterator to `Cursor` when handling a `DupSort` table.
pub struct DupWalker<'cursor, 'tx, T: DupSort, CURSOR: DbDupCursorRO<'tx, T> + Sized> {
///
/// Reason why we have two lifetimes is to distinguish between `'cursor` lifetime
/// and inherited `'tx` lifetime. If there is only one, rust would short circle
/// the Cursor lifetime and it wouldn't be possible to use Walker.
pub struct DupWalker<'cursor, 'tx, T: DupSort, CURSOR: DbDupCursorRO<'tx, T>> {
/// Cursor to be used to walk through the table.
pub cursor: &'cursor mut CURSOR,
/// Value where to start the walk.
pub start: Option<Result<T::Value, Error>>,
/// Phantom data for 'tx.
/// Phantom data for 'tx. As it is only used for `DbDupCursorRO`.
pub _tx_phantom: PhantomData<&'tx T>,
}
impl<'cursor, 'tx, T: DupSort, CURSOR: DbDupCursorRO<'tx, T> + Sized> std::iter::Iterator
impl<'cursor, 'tx, T: DupSort, CURSOR: DbDupCursorRO<'tx, T>> std::iter::Iterator
for DupWalker<'cursor, 'tx, T, CURSOR>
{
type Item = Result<T::Value, Error>;