From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1799EE4998 for ; Wed, 11 Sep 2024 11:33:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6CE6A940029; Wed, 11 Sep 2024 07:33:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 67CFF940021; Wed, 11 Sep 2024 07:33:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 543E2940029; Wed, 11 Sep 2024 07:33:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 3690F940021 for ; Wed, 11 Sep 2024 07:33:14 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id DD1E0A1128 for ; Wed, 11 Sep 2024 11:33:13 +0000 (UTC) X-FDA: 82552246266.19.394E9B1 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf10.hostedemail.com (Postfix) with ESMTP id 4EE57C000D for ; Wed, 11 Sep 2024 11:33:12 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=BJrC1mKu; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf10.hostedemail.com: domain of dakr@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=dakr@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726054307; a=rsa-sha256; cv=none; b=YSOdzpej/7e5TR/2tsGaT8rOsCiS6w6C+IUqzQvgpMsPBQCFASpNq3o94ZXbqQmwe69pvJ 71lRyb2pjiMcsmqM44Udz3FDIPrXZpqc/L8yY4vxJZLQ6OnSzHkgeuC6nP2qKIxO55uE5r JfDO67UTP/EeDrP6jsMbeSTeKvQqfGE= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=BJrC1mKu; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf10.hostedemail.com: domain of dakr@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=dakr@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1726054307; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=hozV3gn9UCrjxlndTWKYD8xRpAvHLOY5WYcV6CJmxjY=; b=l4BHV1cVjQrFCbeOyWnblSMl2ZY2gLBuJ5L7983mXJh2AcE4zSBKSLiU3FDWomnXTyScz8 9MQGUrynew4zi4XNdHAMnmULosI+hUuFDW1otShAEtKzaJ0oDLuYFDgEP+jIXDv03qkwgj rZUNtlPk0Inxtg5BM33TW4EBgPnaODM= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 226F5A44B68; Wed, 11 Sep 2024 11:33:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A79ECC4CEC5; Wed, 11 Sep 2024 11:33:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726054391; bh=d/6BYN/hz0vb6byjvWNc4phCG22oIwVbCnvyfL1nmP8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=BJrC1mKuzmCf5h4ZN/N4P6hYPuKbfXWRIhz0oMROBeEZug+h/+T4pMtUcsWl7lkTX 8To1SmRdKnLcEFd2JLUEET9DFIq7A/Hm1LW//VzLbYGoFXDbZezCETlCRMmSAky0su vrpjyzkqVZnYdsUJY3MFIrYJyiXQpSJDb4v5J+QPpS44wOQwMambL/KQrI7LiEHJG3 vYmAWyrZKU07KfA1nPIQVwji9pk2vPfY30ktwgAqfk7jWt76BH+fxJZvtf7CLutq7n i0YqtLiubl8yuDc377zIFUzNZn+VaFDwdOJtUVYRFWk5uGQ/67UZhWPe1fI0C/A9Mq 7GP4I/vtLMONw== Date: Wed, 11 Sep 2024 13:33:03 +0200 From: Danilo Krummrich To: Benno Lossin Cc: ojeda@kernel.org, alex.gaynor@gmail.com, wedsonaf@gmail.com, boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, a.hindborg@samsung.com, aliceryhl@google.com, akpm@linux-foundation.org, daniel.almeida@collabora.com, faith.ekstrand@collabora.com, boris.brezillon@collabora.com, lina@asahilina.net, mcanal@igalia.com, zhiw@nvidia.com, cjia@nvidia.com, jhubbard@nvidia.com, airlied@redhat.com, ajanulgu@redhat.com, lyude@redhat.com, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v6 15/26] rust: alloc: implement `collect` for `IntoIter` Message-ID: References: <20240816001216.26575-1-dakr@kernel.org> <20240816001216.26575-16-dakr@kernel.org> <747b8c1c-cb7b-422e-b6a0-ea863cc37f0a@proton.me> <503abe24-fbac-440a-a063-fc30a2a6bd77@proton.me> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <503abe24-fbac-440a-a063-fc30a2a6bd77@proton.me> X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 4EE57C000D X-Stat-Signature: j39d4zrx76tkwgwssuao1m8mwhy6ex3m X-Rspam-User: X-HE-Tag: 1726054392-235419 X-HE-Meta: U2FsdGVkX1/EuGDn7+FVYxnjcSkvYrWOJfunFtIFY7Qmp4Rx1RtJYWj5SXwZATReNDHrUds0r0VMWirqAS+RexdMDNi9bApm7+ahEOh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kBnKEVm2je332YRdo5R9Bf1NuRtw63eJpf6mV6z92rRZ/j4gOy6eK+ng7HjLGXiFlTnVdcB1Fz7CRnCH8yt+4QR11EkceEFzPA37timx+hFMv/bCws2yu4= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Wed, Sep 11, 2024 at 08:53:24AM +0000, Benno Lossin wrote: > On 11.09.24 02:22, Danilo Krummrich wrote: > > On Tue, Sep 10, 2024 at 08:12:24PM +0000, Benno Lossin wrote: > >> On 16.08.24 02:10, Danilo Krummrich wrote: > >>> + /// Same as `Iterator::collect` but specialized for `Vec`'s `IntoIter`. > >>> + /// > >>> + /// Currently, we can't implement `FromIterator`. There are a couple of issues with this trait > >>> + /// in the kernel, namely: > >>> + /// > >>> + /// - Rust's specialization feature is unstable. This prevents us to optimze for the special > >>> + /// case where `I::IntoIter` equals `Vec`'s `IntoIter` type. > >>> + /// - We also can't use `I::IntoIter`'s type ID either to work around this, since `FromIterator` > >>> + /// doesn't require this type to be `'static`. > >>> + /// - `FromIterator::from_iter` does return `Self` instead of `Result`, hence > >>> + /// we can't properly handle allocation failures. > >>> + /// - Neither `Iterator::collect` nor `FromIterator::from_iter` can handle additional allocation > >>> + /// flags. > >>> + /// > >>> + /// Instead, provide `IntoIter::collect`, such that we can at least convert a `IntoIter` into a > >>> + /// `Vec` again. > >> > >> I think it's great that you include this in the code, but I don't think > >> that it should be visible in the documentation, > > > > Why not? I think this information is valuable for users of this API. > > If you want to keep it, then I don't mind, but I would still move it > underneath `Examples` and add a section header `# Implementation > Details` or similar. Sure, we can do that. > > --- > Cheers, > Benno > > >> can you move it under > >> the `Examples` section and turn it into normal comments? > >> > >>> + /// > >>> + /// Note that `IntoIter::collect` doesn't require `Flags`, since it re-uses the existing backing > >>> + /// buffer. However, this backing buffer may be shrunk to the actual count of elements. > >>> + /// > >>> + /// # Examples > >>> + /// > >>> + /// ``` > >>> + /// let v = kernel::kvec![1, 2, 3]?; > >>> + /// let mut it = v.into_iter(); > >>> + /// > >>> + /// assert_eq!(it.next(), Some(1)); > >>> + /// > >>> + /// let v = it.collect(GFP_KERNEL); > >>> + /// assert_eq!(v, [2, 3]); > >>> + /// > >>> + /// # Ok::<(), Error>(()) > >>> + /// ``` > >>> + pub fn collect(self, flags: Flags) -> Vec { >