[PATCH 2/3] rust: xarray: implement Default for AllocKind
From: Tamir Duberstein
Date: Tue Jul 01 2025 - 12:28:08 EST
Most users are likely to want 0-indexed arrays. Clean up the
documentation test accordingly.
Signed-off-by: Tamir Duberstein <tamird@xxxxxxxxx>
---
rust/kernel/xarray.rs | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/rust/kernel/xarray.rs b/rust/kernel/xarray.rs
index 436faad99c89..bbce54ec695c 100644
--- a/rust/kernel/xarray.rs
+++ b/rust/kernel/xarray.rs
@@ -24,10 +24,11 @@
/// # Examples
///
/// ```rust
-/// use kernel::alloc::KBox;
-/// use kernel::xarray::{AllocKind, XArray};
+/// # use kernel::alloc::KBox;
+/// # use kernel::xarray::XArray;
+/// # use pin_init::stack_pin_init;
///
-/// let xa = KBox::pin_init(XArray::new(AllocKind::Alloc1), GFP_KERNEL)?;
+/// stack_pin_init!(let xa = XArray::new(Default::default()));
///
/// let dead = KBox::new(0xdead, GFP_KERNEL)?;
/// let beef = KBox::new(0xbeef, GFP_KERNEL)?;
@@ -75,8 +76,10 @@ fn drop(self: Pin<&mut Self>) {
}
/// Flags passed to [`XArray::new`] to configure the array's allocation tracking behavior.
+#[derive(Default)]
pub enum AllocKind {
/// Consider the first element to be at index 0.
+ #[default]
Alloc,
/// Consider the first element to be at index 1.
Alloc1,
--
2.50.0