]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
rust: alloc: add doc test for `Vec::extend_with`
authorHsiu Che Yu <yu.whisper.personal@gmail.com>
Sat, 25 Apr 2026 10:16:18 +0000 (18:16 +0800)
committerDanilo Krummrich <dakr@kernel.org>
Tue, 12 May 2026 12:00:03 +0000 (14:00 +0200)
Add a doc test for `Vec::extend_with` demonstrating basic usage and the
zero-length case.

Signed-off-by: Hsiu Che Yu <yu.whisper.personal@gmail.com>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Tested-by: Alexandre Courbot <acourbot@nvidia.com>
Link: https://patch.msgid.link/a02bc604cde78ba505441a5555400e6f575e8a8a.1777111268.git.yu.whisper.personal@gmail.com
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
rust/kernel/alloc/kvec.rs

index 0432864d3c3cc95a7568659dd684b1f80f35f58e..76cbcfb73be2bcda723d65f1da6aee34edd2cf11 100644 (file)
@@ -849,6 +849,24 @@ impl<T> Vec<T, KVmalloc> {
 
 impl<T: Clone, A: Allocator> Vec<T, A> {
     /// 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(());