Skip to content

Commit

Permalink
struct DisjointMut: Add const fn new, as previously there was onl…
Browse files Browse the repository at this point in the history
…y `fn default`.
  • Loading branch information
kkysen committed Apr 13, 2024
1 parent 11afa8e commit a993fde
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/disjoint_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ pub struct DisjointMut<T: ?Sized + AsMutPtr> {
inner: UnsafeCell<T>,
}

impl<T: AsMutPtr> DisjointMut<T> {
pub const fn new(value: T) -> Self {
Self {
inner: UnsafeCell::new(value),
#[cfg(debug_assertions)]
bounds: debug::DisjointMutAllBounds::new(),
}
}
}

#[cfg_attr(not(debug_assertions), repr(transparent))]
pub struct DisjointMutGuard<'a, T: ?Sized + AsMutPtr, V: ?Sized> {
slice: &'a mut V,
Expand Down Expand Up @@ -443,6 +453,15 @@ mod debug {
immutable: Mutex<Vec<DisjointMutBounds>>,
}

impl DisjointMutAllBounds {
pub const fn new() -> Self {
Self {
mutable: Mutex::new(Vec::new()),
immutable: Mutex::new(Vec::new()),
}
}
}

// Inline so that the thread doesn't switch during this call,
// which seems to happen (the backtrace ends in this call).
#[inline(always)]
Expand Down

0 comments on commit a993fde

Please sign in to comment.