We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
From
Clone for OnceLock<T>
1 parent d806608 commit cced652Copy full SHA for cced652
1 file changed
library/std/src/sync/once_lock.rs
@@ -626,14 +626,7 @@ impl<T: fmt::Debug> fmt::Debug for OnceLock<T> {
626
impl<T: Clone> Clone for OnceLock<T> {
627
#[inline]
628
fn clone(&self) -> OnceLock<T> {
629
- let cell = Self::new();
630
- if let Some(value) = self.get() {
631
- match cell.set(value.clone()) {
632
- Ok(()) => (),
633
- Err(_) => unreachable!(),
634
- }
635
636
- cell
+ self.get().cloned().map_or_default(Self::from)
637
}
638
639
0 commit comments