diff --git a/src/disjoint_mut.rs b/src/disjoint_mut.rs index 52bf6ad4b..ddbbc35fd 100644 --- a/src/disjoint_mut.rs +++ b/src/disjoint_mut.rs @@ -263,17 +263,10 @@ impl DisjointMut { /// references to avoid other potential memory safety issues due to racy /// access. #[cfg_attr(debug_assertions, track_caller)] - pub unsafe fn index_mut<'a, I>( - &'a self, - index: I, - ) -> DisjointMutGuard<'a, T, <[::Target] as Index>::Output> + pub unsafe fn index_mut<'a, I>(&'a self, index: I) -> DisjointMutGuard<'a, T, I::Output> where I: Into + Clone, - [::Target]: IndexMut, - I: DisjointMutIndex< - [::Target], - Output = <[::Target] as Index>::Output, - >, + I: DisjointMutIndex<[::Target]>, { let bounds = index.clone().into(); // SAFETY: The safety preconditions of `index` and `index_mut` imply @@ -305,17 +298,10 @@ impl DisjointMut { /// /// [`index_mut`]: DisjointMut::index_mut #[cfg_attr(debug_assertions, track_caller)] - pub fn index<'a, I>( - &'a self, - index: I, - ) -> DisjointImmutGuard<'a, T, <[::Target] as Index>::Output> + pub fn index<'a, I>(&'a self, index: I) -> DisjointImmutGuard<'a, T, I::Output> where I: Into + Clone, - [::Target]: Index, - I: DisjointMutIndex< - [::Target], - Output = <[::Target] as Index>::Output, - >, + I: DisjointMutIndex<[::Target]>, { let bounds = index.clone().into(); // SAFETY: The safety preconditions of `index` and `index_mut` imply @@ -556,6 +542,20 @@ impl From> for Bounds { } } +/// A majority of our slice ranges are of the form `[start..][..len]`. +/// This is easy to express with normal slices where we can do the slicing multiple times, +/// but with [`DisjointMut`], that's harder, so this adds support for +/// `.index((start.., ..len))` to achieve the same. +/// It's not as clear what it means initially, but we use this idiom so much +/// I think it might be worth it for clarity through brevity. +impl From<(RangeFrom, RangeTo)> for Bounds { + fn from((start, len): (RangeFrom, RangeTo)) -> Self { + Self { + range: start.start..start.start + len.end, + } + } +} + trait SliceBounds: Into + Clone + Debug {} impl SliceBounds for Range {} @@ -563,6 +563,7 @@ impl SliceBounds for RangeFrom {} impl SliceBounds for RangeInclusive {} impl SliceBounds for RangeTo {} impl SliceBounds for RangeToInclusive {} +impl SliceBounds for (RangeFrom, RangeTo) {} impl DisjointMutIndex<[T]> for usize { type Output = <[T] as Index>::Output;