From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 58198152526 for ; Thu, 25 Apr 2024 21:57:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.43.22 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714082224; cv=none; b=gZ6fuIiImhTaVuGw2MwcGX0VzpeFOxP2bFoICJKbffE22vqNQSUloausbJ8iZkWxUzdWChXPmByA3T2eb+K3QsAUfFcOGoqIbZmwbBKFuUica8NIx+UpK1hys2vPC+ssrTPAgf55jm94vVxhmnJWamJUj13gx/Lb1EX+va1uHyY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714082224; c=relaxed/simple; bh=2AC9sknLoDsBrHZj6JPOUgXsHl0ckGSbKEILsuBcFn8=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=T0zGLi1eOxaaZ0BRQBMHfa87MPtEs5pYqP6CyVjDSmCpIZ+M56+Mnbd9iMkyCpt4Zo3wn8YtLcx9klPRgsvHl+5dCYd50olm2kMbyJs8UzZrCDRpziA8JYKNTbS9m2bK0oWxm/W/Vl3Pu6vMjFUM4K9JFa83R7nBF4e2Z2Aidfg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me; spf=pass smtp.mailfrom=proton.me; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b=SiqyAVSj; arc=none smtp.client-ip=185.70.43.22 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=proton.me Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b="SiqyAVSj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=xoici6hpxjgnho75p7nsvwzjhm.protonmail; t=1714082219; x=1714341419; bh=ssR1QDbWXYl4zvVV2r1hbcZe90jbbir7db4PC/qkIxw=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=SiqyAVSjPIZTVEUW7Y+8oEW/BRlMJBDBE86ccDZJeHaExhb9IPkM8YozY6go0x13h W/s9+m85Ibcwodaw/VIWgzEj51Y5I2Eu9YqSzdZsyjcbI/0gy3Pa1EBEroAW3FkeEf u9Qg4hMbMnzpj9xP7GzoHCTOCSXfwodJpDFfuC3RC9wl4AEcOPWoKVUL8SE+XU+1p6 2KLmWzqMDSbaDctlxAyDQlPmuqmlKetc7JvI9wU2HvLlNddQ956r9EGyzgy17numSU ldE6nEkbebDpV+WZSoL4NoYfoj2Aw7KEzpsz6iPE6r6JkAN5sWftXBuqLLH2fP4uzi bEva6PwM7ZNMg== Date: Thu, 25 Apr 2024 21:56:54 +0000 To: Matt Gilbride , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Alice Ryhl , Greg Kroah-Hartman , =?utf-8?Q?Arve_Hj=C3=B8nnev=C3=A5g?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Carlos Llamas , Suren Baghdasaryan , Christian Brauner From: Benno Lossin Cc: Rob Landley , Davidlohr Bueso , Michel Lespinasse , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 2/5] rust: rbtree: add `RBTreeIterator` Message-ID: <85fdf6ae-3838-46ff-828f-3179cbad1d30@proton.me> In-Reply-To: References: <20240418-b4-rbtree-v3-0-323e134390ce@google.com> <20240418-b4-rbtree-v3-2-323e134390ce@google.com> Feedback-ID: 71780778:user:proton X-Pm-Message-ID: 8f60004c9bd63e1dddb642f104a09560ba8a6505 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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 { >> + type Item =3D (&'a K, &'a V); >> + type IntoIter =3D 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>, >> + next: *mut bindings::rb_node, >> +} >> + >> +// SAFETY: The [`RBTreeIterator`] gives out immutable references to K a= nd 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> {} >=20 > 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)`. --=20 Cheers, Benno