From nobody Sun Oct 5 20:04:28 2025 Received: from out-186.mta1.migadu.com (out-186.mta1.migadu.com [95.215.58.186]) (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 0158A23B61E for ; Thu, 31 Jul 2025 02:51:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.186 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753930302; cv=none; b=S8rVRqUYc2auOd20MRo5a8cYD1Y33lxX2GWfNG49S6+pC8ohceNjG3ozaWAm2hoKt+vcS+Z7ZRcOPtI4aocbYKEyskZ8ytqaOwkPW4Fc4K54zA+E8op6VXbck/NyaDz819FQVucfQxa3xhVBnvlz8PFl5fmPWaiwy+x+L6mdLPc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753930302; c=relaxed/simple; bh=9/G+VzbLnCvllhDTOgiQ2Sk38pdqY+APu0P5uvfePJI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mdODCgpOfaMMYWMX+ck9dn0BW6Jj8RFjsYqhE9WdkteDHCFBJNkglv3kVNDYXwXqxJRvCFujMj6rr//6BFqrhKCJRN2sZ1CCp6ikSy5j0k7IWofhiQDg5mJuI5hoHVTO89mVvdAplCJLPIFKMg6ZsT0y4F+LDSZzgLI7ahVinNA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=LBA+YI2t; arc=none smtp.client-ip=95.215.58.186 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="LBA+YI2t" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1753930299; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=b7o5QFFXkTqfGSQIOzQItEm5RkP0xLYBE9BClHfTVcg=; b=LBA+YI2t/31wy8g1dqhL5GKUBQl+hNu2oSy7/xXop0VV7Y//jw5RGjpqQrJkhAMv1+SSOm KKh7Ol9od6G4e3OPliq5nF6yaL8W0fW044+XZ8N7G8K2zlnBtinOYVzb7lNcBknYcJHUfd btnIKNMmHrvtxGggSF+2qTvhMc57/CE= From: Hui Zhu To: Danilo Krummrich , Lorenzo Stoakes , Vlastimil Babka , "Liam R . Howlett" , Uladzislau Rezki , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , bjorn3_gh@protonmail.com, Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, vitaly.wool@konsulko.se Cc: Hui Zhu , Geliang Tang , Kunwu Chan Subject: [PATCH v7 2/3] rust: alloc: kvec: add doc example for as_slice method Date: Thu, 31 Jul 2025 10:50:06 +0800 Message-ID: <4e7f396f38ed8a780f863384bfc3d7de135ef3ea.1753929369.git.zhuhui@kylinos.cn> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Hui Zhu Add a practical usage example to the documentation of KVec::as_slice() showing how to: Create a new KVec. Push elements into it. Convert to a slice via as_slice(). Co-developed-by: Geliang Tang Signed-off-by: Geliang Tang Signed-off-by: Hui Zhu Reviewed-by: Alice Ryhl Reviewed-by: Kunwu Chan --- rust/kernel/alloc/kvec.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/rust/kernel/alloc/kvec.rs b/rust/kernel/alloc/kvec.rs index 92d0ed3f302e..f57e08c64929 100644 --- a/rust/kernel/alloc/kvec.rs +++ b/rust/kernel/alloc/kvec.rs @@ -224,6 +224,16 @@ unsafe fn dec_len(&mut self, count: usize) -> &mut [T]= { } =20 /// Returns a slice of the entire vector. + /// + /// # Examples + /// + /// ``` + /// let mut v =3D KVec::new(); + /// v.push(1, GFP_KERNEL)?; + /// v.push(2, GFP_KERNEL)?; + /// assert_eq!(v.as_slice(), &[1, 2]); + /// # Ok::<(), Error>(()) + /// ``` #[inline] pub fn as_slice(&self) -> &[T] { self --=20 2.43.0