Skip to content

Commit

Permalink
impl Clone
Browse files Browse the repository at this point in the history
  • Loading branch information
harryscholes committed Feb 29, 2024
1 parent 84320ae commit 9e897e4
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ impl<T> Arc<T> {
Self { inner }
}

pub fn clone(&self) -> Self {
// Use relaxed ordering because the order of this relative to other operations doesn't matter.
self.inner().count.fetch_add(1, Relaxed);

Self { inner: self.inner }
}

pub fn try_unwrap(this: Arc<T>) -> Result<T, Arc<T>> {
// When only one reference exists, we release ownership of the data.
if this
Expand Down Expand Up @@ -65,6 +58,15 @@ impl<T> Arc<T> {
}
}

impl<T> Clone for Arc<T> {
fn clone(&self) -> Self {
// Use relaxed ordering because the order of this relative to other operations doesn't matter.
self.inner().count.fetch_add(1, Relaxed);

Self { inner: self.inner }
}
}

impl<T> Drop for Arc<T> {
fn drop(&mut self) {
// When more than one reference exists, we release ownership of the data.
Expand Down

0 comments on commit 9e897e4

Please sign in to comment.