From: Hsiu Che Yu Date: Sat, 25 Apr 2026 10:16:18 +0000 (+0800) Subject: rust: alloc: add doc test for `Vec::extend_with` X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=802ca0008bba0b9a27479580c3c77b9e8095c4ef;p=thirdparty%2Flinux.git rust: alloc: add doc test for `Vec::extend_with` Add a doc test for `Vec::extend_with` demonstrating basic usage and the zero-length case. Signed-off-by: Hsiu Che Yu Reviewed-by: Alexandre Courbot Tested-by: Alexandre Courbot Link: https://patch.msgid.link/a02bc604cde78ba505441a5555400e6f575e8a8a.1777111268.git.yu.whisper.personal@gmail.com Signed-off-by: Danilo Krummrich --- diff --git a/rust/kernel/alloc/kvec.rs b/rust/kernel/alloc/kvec.rs index 0432864d3c3cc..76cbcfb73be2b 100644 --- a/rust/kernel/alloc/kvec.rs +++ b/rust/kernel/alloc/kvec.rs @@ -849,6 +849,24 @@ impl Vec { impl Vec { /// Extend the vector by `n` clones of `value`. + /// + /// # Examples + /// + /// ``` + /// let mut v = KVec::new(); + /// v.push(1, GFP_KERNEL)?; + /// + /// v.extend_with(3, 5, GFP_KERNEL)?; + /// assert_eq!(&v, &[1, 5, 5, 5]); + /// + /// v.extend_with(2, 8, GFP_KERNEL)?; + /// assert_eq!(&v, &[1, 5, 5, 5, 8, 8]); + /// + /// v.extend_with(0, 3, GFP_KERNEL)?; + /// assert_eq!(&v, &[1, 5, 5, 5, 8, 8]); + /// + /// # Ok::<(), Error>(()) + /// ``` pub fn extend_with(&mut self, n: usize, value: T, flags: Flags) -> Result<(), AllocError> { if n == 0 { return Ok(());