From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 300A23196B9; Wed, 2 Jul 2025 15:40:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751470812; cv=none; b=cpE3HCzTcv+yk6ZjgNWneeGasROFfqVBb0nspZYsGBjubAlFyeV7ioWURVTmGtHpdZGkkNNL9W6VyJzpQEG+7HVasZXlCaz856s9/atpgizNvbMyrd3+tfXL07IXMfy3ha7k9DhmwdE18Wz4eR4lX+nWqN4nJ6Cg+S3YZPO7FwM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751470812; c=relaxed/simple; bh=Nl1aiQlqLwfjxOlqHygtp0TPczUO9+yJInOmHaoNVqs=; h=Mime-Version:Content-Type:Date:Message-Id:Cc:Subject:From:To: References:In-Reply-To; b=TQLWjIxbwko5jSDQ5UgPJinjl5CUWtAmo23+Xl1re2R7JH+KZqROwHcny+8VCrkI61HE/rOmByWtbB1To5td+aLsKg/4mJmsU0ZTWk136gNZiUUEXjDrk4Qr9sdx+vfea0GT3F6LxfMbMGggq4iH6R91ukXJQvpxQ5DvaNIb8WE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bYRVJMTW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bYRVJMTW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48CB5C4CEE7; Wed, 2 Jul 2025 15:40:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751470811; bh=Nl1aiQlqLwfjxOlqHygtp0TPczUO9+yJInOmHaoNVqs=; h=Date:Cc:Subject:From:To:References:In-Reply-To:From; b=bYRVJMTW6KqJ4prbGWr+/MLk3v69Kf43T2YYrJquE/xIK+MZJLz/d9MxhKLXVbllv bTH2Bi1KC45sBKqxy0Zza5/YxJ1j+ZGSB/sIBDVHzdhVfDlFGLdCqN2Is60MVCLpcS ZhQdHqA68/YTVzP8Nw8331Yy+UdkhMMj8rw/Z0fnhu0WGwPODLsPDrwJuf/ITFgWLh O3F9h7+YiQY9ha9wgrbxv7WdjlxAyds/yU+Q/GhFg2JXOS4rilHZRISYqbK7azaysq LASiSfOsPLArnA2RC9gzTYMA/u3a4GLg6/xkwD6v35r8BeZE8Tib5wWWjw0VCIY9Go wXx9+AQXACFnA== Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Wed, 02 Jul 2025 17:40:05 +0200 Message-Id: Cc: "Andreas Hindborg" , "Miguel Ojeda" , "Alex Gaynor" , "Boqun Feng" , "Gary Guo" , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , "Masahiro Yamada" , "Nathan Chancellor" , "Luis Chamberlain" , "Danilo Krummrich" , "Nicolas Schier" , "Trevor Gross" , "Adam Bratschi-Kaye" , , , , "Petr Pavlu" , "Sami Tolvanen" , "Daniel Gomez" , "Simona Vetter" , "Greg KH" , "Fiona Behrens" , "Daniel Almeida" , Subject: Re: [PATCH v14 1/7] rust: sync: add `OnceLock` From: "Benno Lossin" To: "Alice Ryhl" X-Mailer: aerc 0.20.1 References: <20250702-module-params-v3-v14-0-5b1cc32311af@kernel.org> <20250702-module-params-v3-v14-1-5b1cc32311af@kernel.org> In-Reply-To: On Wed Jul 2, 2025 at 5:27 PM CEST, Alice Ryhl wrote: > On Wed, Jul 2, 2025 at 5:07=E2=80=AFPM Benno Lossin w= rote: >> On Wed Jul 2, 2025 at 3:18 PM CEST, Andreas Hindborg wrote: >> > +impl OnceLock { >> > + /// Get a copy of the contained object. >> > + /// >> > + /// Returns [`None`] if the [`OnceLock`] is empty. >> > + pub fn copy(&self) -> Option { >> > + if self.init.load(Acquire) =3D=3D 2 { >> > + // SAFETY: As determined by the load above, the object is= ready for shared access. >> > + Some(unsafe { *self.value.get() }) >> > + } else { >> > + None >> > + } >> >> The impl can just be: >> >> self.as_ref().copied() >> >> Would it make sense for this function to take `self` instead & we make >> the `OnceLock` also `Copy` if `T: Copy`? Maybe not... > > Atomics are not Copy. Ah right... Yeah it probably also isn't useful. --- Cheers, Benno