There was an error while loading. Please reload this page.
From
Clone for OnceLock<T>
1 parent d806608 commit c8351a7Copy full SHA for c8351a7
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
+ if let Some(value) = self.get() { Self::from(value.clone()) } else { Self::new() }
637
}
638
639
0 commit comments