Skip to content

Commit 2bd6fb5

Browse files
tamirdjannau
authored andcommitted
rust: xarray: implement Default for AllocKind
Most users are likely to want 0-indexed arrays. Clean up the documentation test accordingly. Signed-off-by: Tamir Duberstein <tamird@gmail.com>
1 parent cb4d9f8 commit 2bd6fb5

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

rust/kernel/xarray.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ use core::{iter, marker::PhantomData, mem, ptr::NonNull};
2424
/// # Examples
2525
///
2626
/// ```rust
27-
/// use kernel::alloc::KBox;
28-
/// use kernel::xarray::{AllocKind, XArray};
27+
/// # use kernel::alloc::KBox;
28+
/// # use kernel::xarray::XArray;
29+
/// # use pin_init::stack_pin_init;
2930
///
30-
/// let xa = KBox::pin_init(XArray::new(AllocKind::Alloc1), GFP_KERNEL)?;
31+
/// stack_pin_init!(let xa = XArray::new(Default::default()));
3132
///
3233
/// let dead = KBox::new(0xdead, GFP_KERNEL)?;
3334
/// let beef = KBox::new(0xbeef, GFP_KERNEL)?;
@@ -75,8 +76,10 @@ impl<T: ForeignOwnable> PinnedDrop for XArray<T> {
7576
}
7677

7778
/// Flags passed to [`XArray::new`] to configure the array's allocation tracking behavior.
79+
#[derive(Default)]
7880
pub enum AllocKind {
7981
/// Consider the first element to be at index 0.
82+
#[default]
8083
Alloc,
8184
/// Consider the first element to be at index 1.
8285
Alloc1,

0 commit comments

Comments
 (0)