Skip to content

Commit

Permalink
Implement replace() method for AtomicBox
Browse files Browse the repository at this point in the history
This implements a method on `AtomicBox` that will allow you to replace
the inner value with the given one, and without a closure.
  • Loading branch information
brkydnc committed Mar 9, 2024
1 parent 719625d commit 7b41991
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/sync/atomics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ impl<T: Sized> AtomicBox<T> {
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 7b41991

Please sign in to comment.