Expand description
Provably safe abstraction for concurrent, disjoint mutation of contiguous storage.
DisjointMut wraps a collection and allows non-overlapping mutable borrows
through a shared & reference. Like RefCell, it enforces
borrowing rules at runtime — but instead of whole-container borrows, it tracks
ranges and panics only on truly overlapping access.
§Safety Model
By default, every .index() and .index_mut() call validates that the requested
range doesn’t overlap with any outstanding borrow. This makes DisjointMut a
sound safe abstraction: safe code cannot cause undefined behavior.
For performance-critical code that has been audited for correctness, the
DisjointMut::dangerously_unchecked() unsafe constructor skips runtime
tracking. The unsafe boundary ensures that opting out of tracking is an
explicit, auditable decision — not something that can happen via feature
unification or accident.
§Example
use rav1d_disjoint_mut::DisjointMut;
let mut buf = DisjointMut::new(vec![0u8; 100]);
// Borrow two non-overlapping regions simultaneously through &buf:
let a = buf.index(0..50);
let b = buf.index(50..100);
assert_eq!(a.len() + b.len(), 100);Structs§
- Bounds
- Disjoint
Immut Guard - Disjoint
Mut - Wraps an indexable collection to allow unchecked concurrent mutable borrows.
- Disjoint
MutArc Slice - A wrapper around an
Arcof aDisjointMutslice. AnArc<[_]>can be created, but adding aDisjointMutin between requires boxing sinceDisjointMuthas tracking fields. - Disjoint
MutGuard
Traits§
- AsMut
Ptr - Convert from a mutable pointer to a collection to a mutable pointer to the underlying slice without ever creating a mutable reference to the slice.
- Clearable
- Trait for types that support
clear(). - Disjoint
MutIndex - This trait is a stable implementation of
std::slice::SliceIndexto allow for indexing into mutable slice raw pointers. - External
AsMut Ptr - Opt-in trait for external types to participate in
DisjointMut. - Resizable
- Trait for types that support
resize(len, value). Implement this for your container type so thatDisjointMut<YourType>gains a.resize()method. - Resizable
With - Trait for types that support
resize_with(len, f). - Slice
Bounds - Translate
Range - TryResizable
- Fallible version of
Resizable. ReturnsErron allocation failure. - TryResizable
With - Fallible version of
ResizableWith. ReturnsErron allocation failure.
Type Aliases§
- Disjoint
MutSlice DisjointMutalways has tracking fields, so we useBox<[T]>as the backing store for slice-based DisjointMut instances.