Skip to main content

Crate rav1d_disjoint_mut

Crate rav1d_disjoint_mut 

Source
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
DisjointImmutGuard
DisjointMut
Wraps an indexable collection to allow unchecked concurrent mutable borrows.
DisjointMutArcSlice
A wrapper around an Arc of a DisjointMut slice. An Arc<[_]> can be created, but adding a DisjointMut in between requires boxing since DisjointMut has tracking fields.
DisjointMutGuard

Traits§

AsMutPtr
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().
DisjointMutIndex
This trait is a stable implementation of std::slice::SliceIndex to allow for indexing into mutable slice raw pointers.
ExternalAsMutPtr
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 that DisjointMut<YourType> gains a .resize() method.
ResizableWith
Trait for types that support resize_with(len, f).
SliceBounds
TranslateRange
TryResizable
Fallible version of Resizable. Returns Err on allocation failure.
TryResizableWith
Fallible version of ResizableWith. Returns Err on allocation failure.

Type Aliases§

DisjointMutSlice
DisjointMut always has tracking fields, so we use Box<[T]> as the backing store for slice-based DisjointMut instances.