Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp493262lqo; Thu, 16 May 2024 12:04:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUrfsmoLxaVpqqunLjL64s8lgfyXuUF7IHUhiUL4ChRW+UtiApm7adfXSvHHlGp87iR0csk8nanJnaHorsbPXuuI4bNn7vKKvM2etbadg== X-Google-Smtp-Source: AGHT+IFxhWU8r6AYcRzlxOquDZaVoD5+plKGHgl4fcr4hlSZWFzX8JL1GWTrdkeovRDHCyQJU0lL X-Received: by 2002:a17:90b:118b:b0:2b2:b00b:a341 with SMTP id 98e67ed59e1d1-2b6cc34232amr18616436a91.8.1715886289776; Thu, 16 May 2024 12:04:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715886289; cv=pass; d=google.com; s=arc-20160816; b=IZPmqcq8DctygcmAN7CUYVd1LW+dO9GsrPFufwi7ae1UBSWle5sa7vcaw1ZBLGgUMi sGSDfd+eNDW40w/gK8dw8gn9XWLHzSf21O8RS9U3pQ8BM/dbaUcu+oCZbadW7T5yedvW oUS5RQ0w3xN/hgkbaA8ZHCbhBFlXK9Z8xJIjc7cpuB6z2ocbNN5ki+v0f87RJpxd/SQW MqDW3ahFMgMyRhRL8EttyfckZeyxkaaiXscYeMxciJXday+GeAorpV0cLNtawmzZoy95 iPdb8hlIJV4jguN7LDyXeq20BKBWHxy2wUmQErR3lMtiG9jm/8dRfP6v9brD1kTaLzhZ IT+w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=RM2bpcKeFIOuwJsUXBWZw4CVFhC5QI3+qCCBvqPUBZo=; fh=DGE/Rt7UZyKJ8ICVIgmeDLsrdvw5JULr/fcEfbQDVFQ=; b=ZOsGV5AO6SMET628YK3ZhpuzyrYZcJBzesnJxzN/buA7L4F7nd7+ZeZSXUKRwkPjN/ SBwOHV00zv1gTPrk6CFlLzT4qinPgM42E4xmr4KX4NpCfO4ZEGBc+osUli8yjtF2n3gs /ZAe8BysQovDj/+nBFDyJQaWPDZiOiWap1Sm2d/BIVu/rYQKMtKClrh/AUEMnCmhKTxq qGUrnOyge2ttpcXJtxmtyy0uMnLHev0GiDVFe/TCjwaAp8cdtQ4q66ivwNVvirKe6qvR rR7DNmVCoxk6KfEBxUtWH5Xan2XZ5UuNWOAh+Ku6ECNPYp65GZctzJDg+V3pP/hIV5FL dnkg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@cisco.com header.s=iport header.b=Y45+4JjE; arc=pass (i=1 spf=pass spfdomain=cisco.com dkim=pass dkdomain=cisco.com dmarc=pass fromdomain=cisco.com); spf=pass (google.com: domain of linux-kernel+bounces-181493-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181493-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cisco.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2b5e02ba92fsi15520560a91.1.2024.05.16.12.04.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 12:04:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-181493-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@cisco.com header.s=iport header.b=Y45+4JjE; arc=pass (i=1 spf=pass spfdomain=cisco.com dkim=pass dkdomain=cisco.com dmarc=pass fromdomain=cisco.com); spf=pass (google.com: domain of linux-kernel+bounces-181493-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181493-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cisco.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 60488283241 for ; Thu, 16 May 2024 19:04:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 18206157E6E; Thu, 16 May 2024 19:04:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=cisco.com header.i=@cisco.com header.b="Y45+4JjE" Received: from aer-iport-4.cisco.com (aer-iport-4.cisco.com [173.38.203.54]) (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 F39C5156F29; Thu, 16 May 2024 19:04:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=173.38.203.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715886263; cv=none; b=ngVcwjV8uUEcAvdUUzhP+kU2fvBgkvvoj/dOzaO+DsSssmgHf7RLlvP6fE+gljTtVpPySn3uaiFNGXdCF6yaaI6M4FF8zkKfw1i7sBHfryEyEsIaQcVwaRQ7u2xEcpFY89g4AZFiQs6PNwnAxbf50fnShvOukJ8FrDi2i3BHNF4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715886263; c=relaxed/simple; bh=0lJ0FxB1P4rcK9zFSRBA5T+g6CrZ0Gf7SJqvtne45QA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Y0YChVzG+7YlkB/RruhQ8P4zdQh/8NLtREtAVi72qcclgvJyF0DQxfJwiU+POYC1N1uKoNa9SjKdfu6M3egmyGjppE/rZpVTh+ZoTBff+fr49kHSjQWmeuhrGervMP+FUOHRHpvZpPH1E3VuAxR0Ko+TqoA96COFPOhMzXkuoeI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=cisco.com; spf=pass smtp.mailfrom=cisco.com; dkim=pass (1024-bit key) header.d=cisco.com header.i=@cisco.com header.b=Y45+4JjE; arc=none smtp.client-ip=173.38.203.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=cisco.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cisco.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cisco.com; i=@cisco.com; l=967; q=dns/txt; s=iport; t=1715886261; x=1717095861; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RM2bpcKeFIOuwJsUXBWZw4CVFhC5QI3+qCCBvqPUBZo=; b=Y45+4JjEVPEgetC8nH5A6haMkizYINtaHu4gEwAurckM5okiDt6f9MGX 4hSirA1iB/qHoK8jYHnArjafGhS2YfzS2/jNhdcMHaMUhJUYcJf2b9jy0 VN0SHSofetW/JSq62Ycf6VFXjHDhFkSNn2hdeKmGh/+mXdEY1ytVaH8yp Q=; X-CSE-ConnectionGUID: MAYFYa3ZSRKzGDsl4DkK+w== X-CSE-MsgGUID: XZR3mbPyTBmG61iWLKTEaQ== X-IronPort-AV: E=Sophos;i="6.08,165,1712620800"; d="scan'208";a="12379874" Received: from aer-iport-nat.cisco.com (HELO aer-core-11.cisco.com) ([173.38.203.22]) by aer-iport-4.cisco.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 May 2024 19:04:19 +0000 Received: from localhost (ams3-vpn-dhcp4879.cisco.com [10.61.83.14]) (authenticated bits=0) by aer-core-11.cisco.com (8.15.2/8.15.2) with ESMTPSA id 44GJ4IDD020825 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 16 May 2024 19:04:18 GMT From: Ariel Miculas To: rust-for-linux@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, tycho@tycho.pizza, brauner@kernel.org, viro@zeniv.linux.org.uk, ojeda@kernel.org, alex.gaynor@gmail.com, wedsonaf@gmail.com, shallyn@cisco.com, Ariel Miculas Subject: [RFC PATCH v3 14/22] rust: kernel: add from_iter_fallible for Vec Date: Thu, 16 May 2024 22:03:37 +0300 Message-Id: <20240516190345.957477-15-amiculas@cisco.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240516190345.957477-1-amiculas@cisco.com> References: <20240516190345.957477-1-amiculas@cisco.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Authenticated-User: amiculas@cisco.com X-Outbound-SMTP-Client: 10.61.83.14, ams3-vpn-dhcp4879.cisco.com X-Outbound-Node: aer-core-11.cisco.com This function takes an iterator and creates a new vector with its elements. It is used in multiple places in the PuzzleFS code. Signed-off-by: Ariel Miculas --- rust/kernel/alloc/vec_ext.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/rust/kernel/alloc/vec_ext.rs b/rust/kernel/alloc/vec_ext.rs index 6ad0b6da45d3..cbc8b06183d7 100644 --- a/rust/kernel/alloc/vec_ext.rs +++ b/rust/kernel/alloc/vec_ext.rs @@ -132,6 +132,18 @@ fn resize(&mut self, new_len: usize, value: T, flags: Flags) -> Result<(), Alloc { self.resize_with(new_len, flags, || value.clone()) } + + /// See https://doc.rust-lang.org/std/vec/struct.Vec.html#examples-31 + fn from_iter_fallible( + iter: impl Iterator, + flags: Flags, + ) -> Result, AllocError> { + let mut vec = Vec::new(); + for value in iter { + vec.push(value, flags)?; + } + Ok(vec) + } } impl VecExt for Vec { -- 2.34.1