lkml.org 
[lkml]   [2024]   [Apr]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v3 2/5] rust: rbtree: add `RBTreeIterator`
On 25.04.24 23:45, Benno Lossin wrote:
> On 18.04.24 16:15, Matt Gilbride wrote:
>> @@ -373,6 +416,56 @@ fn drop(&mut self) {
>> }
>> }
>>
>> +impl<'a, K, V> IntoIterator for &'a RBTree<K, V> {
>> + type Item = (&'a K, &'a V);
>> + type IntoIter = RBTreeIterator<'a, K, V>;
>> +
>> + fn into_iter(self) -> Self::IntoIter {
>> + self.iter()
>> + }
>> +}
>> +
>> +/// An iterator over the nodes of a [`RBTree`].
>> +///
>> +/// Instances are created by calling [`RBTree::iter`].
>> +///
>> +/// # Invariants
>> +/// - `self.next` is a valid pointer.
>> +/// - `self.next` points to a node stored inside of a valid `RBTree`.
>> +pub struct RBTreeIterator<'a, K, V> {
>> + _tree: PhantomData<&'a RBTree<K, V>>,
>> + next: *mut bindings::rb_node,
>> +}
>> +
>> +// SAFETY: The [`RBTreeIterator`] gives out immutable references to K and V, so it has the same
>> +// thread safety requirements as immutable references.
>> +unsafe impl<'a, K: Sync, V: Sync> Send for RBTreeIterator<'a, K, V> {}
>
> The bounds on `K` and `V` look like typos to me. They should be `Send`
> instead.

Oops, scratch this comment, what you wrote is correct, since we treat
`RBTreeIterator` as `(&K, &V)`.

--
Cheers,
Benno


\
 
 \ /
  Last update: 2024-05-27 18:04    [W:0.048 / U:0.616 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site