about summary refs log tree commit diff
path: root/library/std/src/sync/lazy_lock.rs
diff options
context:
space:
mode:
authorChayim Refael Friedman <chayimfr@gmail.com>2024-11-16 22:23:19 +0200
committerChayim Refael Friedman <chayimfr@gmail.com>2024-11-16 22:23:19 +0200
commitb208706b6e2d7b2a218347e4311a05fe3a022d52 (patch)
tree8605f5a302ee09403b64bdf20abf8b99e89544c3 /library/std/src/sync/lazy_lock.rs
parent46e8d20301cb4abe91ab0a4bea43bb085e1d4e4a (diff)
downloadrust-b208706b6e2d7b2a218347e4311a05fe3a022d52.tar.gz
rust-b208706b6e2d7b2a218347e4311a05fe3a022d52.zip
Add `DerefMut` for `Lazy[Cell/Lock]` that delegates to the unstable `force_mut()`
Diffstat (limited to 'library/std/src/sync/lazy_lock.rs')
-rw-r--r--library/std/src/sync/lazy_lock.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/library/std/src/sync/lazy_lock.rs b/library/std/src/sync/lazy_lock.rs
index 40510f56134..4379a1519c6 100644
--- a/library/std/src/sync/lazy_lock.rs
+++ b/library/std/src/sync/lazy_lock.rs
@@ -1,7 +1,7 @@
 use super::once::ExclusiveState;
 use crate::cell::UnsafeCell;
 use crate::mem::ManuallyDrop;
-use crate::ops::Deref;
+use crate::ops::{Deref, DerefMut};
 use crate::panic::{RefUnwindSafe, UnwindSafe};
 use crate::sync::Once;
 use crate::{fmt, ptr};
@@ -312,6 +312,14 @@ impl<T, F: FnOnce() -> T> Deref for LazyLock<T, F> {
     }
 }
 
+#[stable(feature = "lazy_deref_mut", since = "CURRENT_RUSTC_VERSION")]
+impl<T, F: FnOnce() -> T> DerefMut for LazyLock<T, F> {
+    #[inline]
+    fn deref_mut(&mut self) -> &mut T {
+        LazyLock::force_mut(self)
+    }
+}
+
 #[stable(feature = "lazy_cell", since = "1.80.0")]
 impl<T: Default> Default for LazyLock<T> {
     /// Creates a new lazy value using `Default` as the initializing function.