Re: [PATCH v17 5/6] rust: sync: Add SetOnce::reset()

From: lyude

Date: Thu Jun 04 2026 - 14:55:59 EST


On Thu, 2026-06-04 at 11:58 +0000, Alice Ryhl wrote:
> On Wed, Jun 03, 2026 at 03:42:34PM -0400, Lyude Paul wrote:
> > This function simply drops the contents of the SetOnce, given a
> > mutable
> > reference - since that proves we have exclusive access to the
> > SetOnce.
> > Additionally, update the invariants for SetOnce to make it clear as
> > to why
> > this is safe.
> >
> > Signed-off-by: Lyude Paul <lyude@xxxxxxxxxx>
>
> This isn't needed, you can just do:
>
> unsafe { (*this).sgt_res = SetOnce::new() };

I realized after sending this I could also just be using ManuallyDrop
here instead of adding a reset function, which might be a bit clearer
anyhow