From: Tamir Duberstein <tamird@gmail.com>
To: "Andreas Hindborg" <a.hindborg@kernel.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Matthew Wilcox" <willy@infradead.org>,
"Andrew Morton" <akpm@linux-foundation.org>
Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-fsdevel@vger.kernel.org, linux-mm@kvack.org,
Daniel Almeida <daniel.almeida@collabora.com>,
Tamir Duberstein <tamird@gmail.com>
Subject: [PATCH 2/3] rust: xarray: implement Default for AllocKind
Date: Tue, 01 Jul 2025 12:27:18 -0400 [thread overview]
Message-ID: <20250701-xarray-insert-reserve-v1-2-25df2b0d706a@gmail.com> (raw)
In-Reply-To: <20250701-xarray-insert-reserve-v1-0-25df2b0d706a@gmail.com>
Most users are likely to want 0-indexed arrays. Clean up the
documentation test accordingly.
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
---
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
next prev parent reply other threads:[~2025-07-01 16:27 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-01 16:27 [PATCH 0/3] rust: xarray: add `insert` and `reserve` Tamir Duberstein
2025-07-01 16:27 ` [PATCH 1/3] rust: xarray: use the prelude Tamir Duberstein
2025-07-01 16:35 ` Boqun Feng
2025-07-01 16:36 ` Tamir Duberstein
2025-07-01 17:02 ` Boqun Feng
2025-07-01 17:04 ` Tamir Duberstein
2025-07-01 16:27 ` Tamir Duberstein [this message]
2025-07-01 16:27 ` [PATCH 3/3] rust: xarray: add `insert` and `reserve` Tamir Duberstein
2025-07-01 16:56 ` Miguel Ojeda
2025-07-01 17:04 ` Tamir Duberstein
2025-07-02 13:39 ` Daniel Almeida
2025-07-06 8:29 ` Janne Grunau
2025-07-07 13:48 ` Tamir Duberstein
2025-07-06 8:31 ` Alice Ryhl
2025-07-12 19:42 ` [PATCH 0/3] " Janne Grunau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250701-xarray-insert-reserve-v1-2-25df2b0d706a@gmail.com \
--to=tamird@gmail.com \
--cc=a.hindborg@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox