Skip to content

Commit

Permalink
move CursorMut declaration closer to impl
Browse files Browse the repository at this point in the history
  • Loading branch information
kyren committed May 12, 2024
1 parent c6097a7 commit 039c9b5
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions src/linked_hash_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1408,27 +1408,6 @@ pub struct Drain<'a, K, V> {
marker: PhantomData<(K, V, &'a LinkedHashMap<K, V>)>,
}

/// The `CursorMut` struct and its implementation provide the basic mutable Cursor API for Linked
/// lists as proposed in
/// [here](https://github.com/rust-lang/rfcs/blob/master/text/2570-linked-list-cursors.md), with
/// several exceptions:
///
/// - It behaves similarly to Rust's Iterators, returning `None` when the end of the list is
/// reached. A _guard_ node is positioned between the head and tail of the linked list to
/// facilitate this. If the cursor is over this guard node, `None` is returned, signaling the end
/// or start of the list. From this position, the cursor can move in either direction as the
/// linked list is circular, with the guard node connecting the two ends.
/// - The current implementation does not include an `index` method, as it does not track the index
/// of its elements. It provides access to each map entry as a tuple of `(&K, &mut V)`.
///
pub struct CursorMut<'a, K, V, S> {
cur: *mut Node<K, V>,
hash_builder: &'a S,
free: &'a mut Option<NonNull<Node<K, V>>>,
values: &'a mut Option<NonNull<Node<K, V>>>,
table: &'a mut hashbrown::HashTable<NonNull<Node<K, V>>>,
}

impl<K, V> IterMut<'_, K, V> {
#[inline]
pub(crate) fn iter(&self) -> Iter<'_, K, V> {
Expand Down Expand Up @@ -1762,6 +1741,27 @@ impl<'a, K, V> Drop for Drain<'a, K, V> {
}
}

/// The `CursorMut` struct and its implementation provide the basic mutable Cursor API for Linked
/// lists as proposed in
/// [here](https://github.com/rust-lang/rfcs/blob/master/text/2570-linked-list-cursors.md), with
/// several exceptions:
///
/// - It behaves similarly to Rust's Iterators, returning `None` when the end of the list is
/// reached. A _guard_ node is positioned between the head and tail of the linked list to
/// facilitate this. If the cursor is over this guard node, `None` is returned, signaling the end
/// or start of the list. From this position, the cursor can move in either direction as the
/// linked list is circular, with the guard node connecting the two ends.
/// - The current implementation does not include an `index` method, as it does not track the index
/// of its elements. It provides access to each map entry as a tuple of `(&K, &mut V)`.
///
pub struct CursorMut<'a, K, V, S> {
cur: *mut Node<K, V>,
hash_builder: &'a S,
free: &'a mut Option<NonNull<Node<K, V>>>,
values: &'a mut Option<NonNull<Node<K, V>>>,
table: &'a mut hashbrown::HashTable<NonNull<Node<K, V>>>,
}

impl<'a, K, V, S> CursorMut<'a, K, V, S> {
/// Returns an `Option` of the current element in the list, provided it is not the
/// _guard_ node, and `None` overwise.
Expand Down

0 comments on commit 039c9b5

Please sign in to comment.