Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage: into_iter with self by value #12115

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
21 changes: 10 additions & 11 deletions crates/storage/libmdbx-rs/src/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,18 @@ where
}

/// Returns an iterator over the raw key value slices.
#[allow(clippy::needless_lifetimes)]
pub fn iter_slices<'a>(&'a self) -> IntoIter<'a, K, Cow<'a, [u8]>, Cow<'a, [u8]>> {
pub fn iter_slices<'a>(self) -> IntoIter<K, Cow<'a, [u8]>, Cow<'a, [u8]>> {
self.into_iter()
}

/// Returns an iterator over database items.
#[allow(clippy::should_implement_trait)]
pub fn into_iter<Key, Value>(&self) -> IntoIter<'_, K, Key, Value>
pub fn into_iter<Key, Value>(self) -> IntoIter<K, Key, Value>
where
Key: TableObject,
Value: TableObject,
{
IntoIter::new(self.clone(), MDBX_NEXT, MDBX_NEXT)
IntoIter::new(self, MDBX_NEXT, MDBX_NEXT)
}

/// Retrieves a key/data pair from the cursor. Depending on the cursor op,
Expand Down Expand Up @@ -508,7 +507,7 @@ unsafe impl<K> Sync for Cursor<K> where K: TransactionKind {}

/// An iterator over the key/value pairs in an MDBX database.
#[derive(Debug)]
pub enum IntoIter<'cur, K, Key, Value>
pub enum IntoIter<K, Key, Value>
where
K: TransactionKind,
Key: TableObject,
Expand All @@ -535,23 +534,23 @@ where
/// The next and subsequent operations to perform.
next_op: ffi::MDBX_cursor_op,

_marker: PhantomData<(&'cur (), Key, Value)>,
_marker: PhantomData<(Key, Value)>,
},
}

impl<K, Key, Value> IntoIter<'_, K, Key, Value>
impl<K, Key, Value> IntoIter<K, Key, Value>
where
K: TransactionKind,
Key: TableObject,
Value: TableObject,
{
/// Creates a new iterator backed by the given cursor.
fn new(cursor: Cursor<K>, op: ffi::MDBX_cursor_op, next_op: ffi::MDBX_cursor_op) -> Self {
IntoIter::Ok { cursor, op, next_op, _marker: Default::default() }
Self::Ok { cursor, op, next_op, _marker: Default::default() }
}
}

impl<K, Key, Value> Iterator for IntoIter<'_, K, Key, Value>
impl<K, Key, Value> Iterator for IntoIter<K, Key, Value>
where
K: TransactionKind,
Key: TableObject,
Expand Down Expand Up @@ -747,13 +746,13 @@ where
}
}

impl<'cur, K, Key, Value> Iterator for IterDup<'cur, K, Key, Value>
impl<K, Key, Value> Iterator for IterDup<'_, K, Key, Value>
where
K: TransactionKind,
Key: TableObject,
Value: TableObject,
{
type Item = IntoIter<'cur, K, Key, Value>;
type Item = IntoIter<K, Key, Value>;

fn next(&mut self) -> Option<Self::Item> {
match self {
Expand Down
Loading