Skip to content

Commit bf3ab36

Browse files
Darksonnjannau
authored andcommitted
rust: alloc: add Vec::clear
Our custom Vec type is missing the stdlib method `clear`, thus add it. It will be used in the miscdevice sample. Reviewed-by: Benno Lossin <[email protected]> Reviewed-by: Tamir Duberstein <[email protected]> Signed-off-by: Alice Ryhl <[email protected]> Reviewed-by: Greg Kroah-Hartman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Danilo Krummrich <[email protected]>
1 parent 3a2d9f7 commit bf3ab36

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

rust/kernel/alloc/kvec.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,26 @@ where
416416
(ptr, len, capacity)
417417
}
418418

419+
/// Clears the vector, removing all values.
420+
///
421+
/// Note that this method has no effect on the allocated capacity
422+
/// of the vector.
423+
///
424+
/// # Examples
425+
///
426+
/// ```
427+
/// let mut v = kernel::kvec![1, 2, 3]?;
428+
///
429+
/// v.clear();
430+
///
431+
/// assert!(v.is_empty());
432+
/// # Ok::<(), Error>(())
433+
/// ```
434+
#[inline]
435+
pub fn clear(&mut self) {
436+
self.truncate(0);
437+
}
438+
419439
/// Ensures that the capacity exceeds the length by at least `additional` elements.
420440
///
421441
/// # Examples

0 commit comments

Comments
 (0)