Skip to content

Commit 5197196

Browse files
committed
feat: Add threading::make_mut() to allow obtaining a mutable reference to shared data.
This is particularly useful when handling an index file, which may be shared across clones of a repository.
1 parent 7a96a25 commit 5197196

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

gix-features/src/threading.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ mod _impl {
3030
v.write()
3131
}
3232

33+
/// Get a mutable reference to the underlying data, with semantics similar to [Arc::make_mut()].
34+
pub fn make_mut<T: Clone>(this: &mut OwnShared<T>) -> &mut T {
35+
OwnShared::make_mut(this)
36+
}
37+
3338
/// Get a mutable reference through a [`Mutable`] for read-write access.
3439
pub fn lock<T>(v: &Mutable<T>) -> parking_lot::MutexGuard<'_, T> {
3540
v.lock()
@@ -75,6 +80,11 @@ mod _impl {
7580
v.borrow_mut()
7681
}
7782

83+
/// Get a mutable reference to the underlying data, with semantics similar to [Rc::make_mut()].
84+
pub fn make_mut<T: Clone>(this: &mut OwnShared<T>) -> &mut T {
85+
OwnShared::make_mut(this)
86+
}
87+
7888
/// Get a mutable reference through a [`Mutable`] for read-write access.
7989
pub fn lock<T>(v: &Mutable<T>) -> RefMut<'_, T> {
8090
v.borrow_mut()

0 commit comments

Comments
 (0)