public inbox for rust-for-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: "Benno Lossin" <lossin@kernel.org>
To: "Andreas Hindborg" <a.hindborg@kernel.org>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>
Cc: <rust-for-linux@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] rust: sync: add lazy initialization methods to SetOnce
Date: Mon, 16 Feb 2026 00:28:02 +0100	[thread overview]
Message-ID: <DGFXBHXTR8YS.3NUDRE3ZKV7Y6@kernel.org> (raw)
In-Reply-To: <20260215-set-once-lazy-v1-1-6f5bd2efda11@kernel.org>

On Sun Feb 15, 2026 at 9:27 PM CET, Andreas Hindborg wrote:
> @@ -76,10 +79,46 @@ pub fn as_ref(&self) -> Option<&T> {
>          }
>      }
>  
> +    /// Get a reference to the contained object, or populate the [`SetOnce`]
> +    /// with the value returned by `callable` and return a reference to that
> +    /// object.
> +    pub fn as_ref_or_populate_with(&self, callable: impl FnOnce() -> Result<T>) -> Result<&T> {

I would name the argument `create`, but not `callable`. Same below.

Cheers,
Benno

> +        if !self.populate_with(callable)? {
> +            while self.init.load(Acquire) != 2 {
> +                core::hint::spin_loop();
> +            }
> +        }

  reply	other threads:[~2026-02-15 23:28 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-15 20:27 [PATCH] rust: sync: add lazy initialization methods to SetOnce Andreas Hindborg
2026-02-15 23:28 ` Benno Lossin [this message]
2026-02-16  8:46 ` Alice Ryhl
2026-02-16 11:10   ` Andreas Hindborg
2026-02-16 11:26     ` Alice Ryhl
2026-02-16 11:35       ` Alice Ryhl
2026-02-16 13:32         ` Andreas Hindborg
2026-02-27 14:56 ` Gary Guo
2026-02-27 19:15   ` Andreas Hindborg

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=DGFXBHXTR8YS.3NUDRE3ZKV7Y6@kernel.org \
    --to=lossin@kernel.org \
    --cc=a.hindborg@kernel.org \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.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