Skip to content

Commit

Permalink
Merge pull request #25 from brkydnc/master
Browse files Browse the repository at this point in the history
Require `FnOnce` instead of `Fn` in `replace_with`
  • Loading branch information
vertexclique authored Apr 15, 2024
2 parents 719625d + 7966964 commit 690d85e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/sync/atomics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,20 @@ impl<T: Sized> AtomicBox<T> {
/// given closure to the current value
pub fn replace_with<F>(&self, f: F)
where
F: Fn(Arc<T>) -> T,
F: FnOnce(Arc<T>) -> T,
{
let val = self.take();
let new_val = f(val);
let ptr = Arc::into_raw(Arc::new(new_val)) as *mut T;
self.release(ptr);
}

///
/// Atomically replace the inner value with the given one.
pub fn replace(&self, new_val: T) {
let ptr = Arc::into_raw(Arc::new(new_val)) as *mut T;
self.release(ptr);
}
}

impl<T: Sized + PartialEq> PartialEq for AtomicBox<T> {
Expand Down

0 comments on commit 690d85e

Please sign in to comment.