Skip to content

Commit

Permalink
is_unique for arcarray
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellga committed Jul 29, 2024
1 parent 5ee7287 commit 7fbefc0
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/impl_arc_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use alloc::sync::Arc;
use crate::imp_prelude::*;
use alloc::sync::Arc;

/// Methods specific to `ArcArray`.
///
Expand All @@ -17,7 +17,9 @@ where
D: Dimension,
{
/// Returns `true` iff the inner `Arc` is not shared.
pub fn is_unique(&mut self) -> bool {
Arc::get_mut(&mut self.data.0).is_some()
/// If you want to ensure the Arc is not concurrently cloned, you need to provide a `&mut self` to this function.
pub fn is_unique(&self) -> bool {
// Only strong pointers are used in this crate.
Arc::strong_count(&self.data.0) == 1
}
}

0 comments on commit 7fbefc0

Please sign in to comment.