Re: [PATCH] rust: sync: add lazy initialization methods to SetOnce

From: Benno Lossin

Date: Sun Feb 15 2026 - 18:28:20 EST


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();
> + }
> + }