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.
2 parents 719625d + 7966964 commit 690d85eCopy full SHA for 690d85e
src/sync/atomics.rs
@@ -100,13 +100,20 @@ impl<T: Sized> AtomicBox<T> {
100
/// given closure to the current value
101
pub fn replace_with<F>(&self, f: F)
102
where
103
- F: Fn(Arc<T>) -> T,
+ F: FnOnce(Arc<T>) -> T,
104
{
105
let val = self.take();
106
let new_val = f(val);
107
let ptr = Arc::into_raw(Arc::new(new_val)) as *mut T;
108
self.release(ptr);
109
}
110
+
111
+ ///
112
+ /// Atomically replace the inner value with the given one.
113
+ pub fn replace(&self, new_val: T) {
114
+ let ptr = Arc::into_raw(Arc::new(new_val)) as *mut T;
115
+ self.release(ptr);
116
+ }
117
118
119
impl<T: Sized + PartialEq> PartialEq for AtomicBox<T> {
0 commit comments