From: I Hsin Cheng <richard120310@gmail.com>
To: ojeda@kernel.org
Cc: alex.gaynor@gmail.com, boqun.feng@gmail.com, gary@garyguo.net,
bjorn3_gh@protonmail.com, benno.lossin@proton.me,
a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
skhan@linuxfoundation.org, linux-kernel-mentees@lists.linux.dev,
jserv@ccns.ncku.edu.tw, I Hsin Cheng <richard120310@gmail.com>
Subject: [RFC PATCH 1/2] rust: list: Implement normal initializer for ListLinks
Date: Mon, 10 Mar 2025 15:30:39 +0800 [thread overview]
Message-ID: <20250310073040.423383-2-richard120310@gmail.com> (raw)
In-Reply-To: <20250310073040.423383-1-richard120310@gmail.com>
Currently ListLinks only supports to create an initializer through
"new()", which will need further initialization because the return type
of "new()" is "impl Pininit<Self>". Not even "ListLinksSlefPtr" use the
method to create a new instance of "ListLinks".
Implement a normal method to create a new instance of type "ListLinks".
This may be redundant as long as there exist a convenient and proper way
to deal with "ListLinks::new()".
For now it's introduce for the simplicity of examples in the following
patches.
Signed-off-by: I Hsin Cheng <richard120310@gmail.com>
---
rust/kernel/list.rs | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/rust/kernel/list.rs b/rust/kernel/list.rs
index fb93330f4af4..57d75ca16434 100644
--- a/rust/kernel/list.rs
+++ b/rust/kernel/list.rs
@@ -158,6 +158,16 @@ unsafe impl<const ID: u64> Send for ListLinks<ID> {}
unsafe impl<const ID: u64> Sync for ListLinks<ID> {}
impl<const ID: u64> ListLinks<ID> {
+ /// Create a new instance of this type.
+ pub fn new_link() -> Self {
+ ListLinks {
+ inner: Opaque::new(ListLinksFields {
+ prev: ptr::null_mut(),
+ next: ptr::null_mut(),
+ }),
+ }
+ }
+
/// Creates a new initializer for this type.
pub fn new() -> impl PinInit<Self> {
// INVARIANT: Pin-init initializers can't be used on an existing `Arc`, so this value will
--
2.43.0
next prev parent reply other threads:[~2025-03-10 7:30 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-10 7:30 [RFC PATCH 0/2] rust: list: Add examples for linked list I Hsin Cheng
2025-03-10 7:30 ` I Hsin Cheng [this message]
2025-03-10 9:44 ` [RFC PATCH 1/2] rust: list: Implement normal initializer for ListLinks Alice Ryhl
2025-03-10 11:14 ` I Hsin Cheng
2025-03-10 11:44 ` Alice Ryhl
2025-03-10 7:30 ` [RFC PATCH 2/2] rust: list: Add examples for linked list I Hsin Cheng
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=20250310073040.423383-2-richard120310@gmail.com \
--to=richard120310@gmail.com \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=gary@garyguo.net \
--cc=jserv@ccns.ncku.edu.tw \
--cc=linux-kernel-mentees@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=tmgross@umich.edu \
/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