Skip to content

Commit 7a65b6e

Browse files
authored
Make StableArena::get_disjoint_mut return array instead of tuple (#1988)
make get_disjoint_mut return array instead of tuple this mirrors Rust's Vec::get_disjoint_mut API more closely.
1 parent 19ccb31 commit 7a65b6e

2 files changed

Lines changed: 5 additions & 8 deletions

File tree

crates/collections/src/arena/stable_arena.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ where
162162
/// - If `keys[0]` and `keys[1]` refer to the same item, a.k.a. aliasing each other.
163163
/// - If `keys[0]` or `keys[1]` is out of bounds for the arena.
164164
#[inline]
165-
pub fn get_disjoint_mut(&mut self, keys: [Key; 2]) -> Result<(&mut T, &mut T), ArenaError> {
165+
pub fn get_disjoint_mut(&mut self, keys: [Key; 2]) -> Result<[&mut T; 2], ArenaError> {
166166
let [a, b] = keys;
167167
self.items
168168
.get_disjoint_mut([a.into_usize(), b.into_usize()])
@@ -392,7 +392,7 @@ mod tests {
392392
let mut arena: Arena = (0..10).collect();
393393
*arena.get_mut(3).unwrap() = 30;
394394
assert_eq!(arena.get(3).unwrap(), &30);
395-
let (a, b) = arena.get_disjoint_mut([1, 8]).unwrap();
395+
let [a, b] = arena.get_disjoint_mut([1, 8]).unwrap();
396396
*a = -1;
397397
*b = -8;
398398
assert_eq!((arena[1], arena[8]), (-1, -8));

crates/collections/src/arena/stable_vec.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,7 @@ impl<T> StableVec<T> {
128128
/// - If `indices[0]` and `indices[1]` refer to the same item, a.k.a. aliasing each other.
129129
/// - If `indices[0]` or `indices[1]` is out of bounds for the arena.
130130
#[inline]
131-
pub fn get_disjoint_mut(
132-
&mut self,
133-
indices: [usize; 2],
134-
) -> Result<(&mut T, &mut T), ArenaError> {
131+
pub fn get_disjoint_mut(&mut self, indices: [usize; 2]) -> Result<[&mut T; 2], ArenaError> {
135132
let [a, b] = indices;
136133
if a == b {
137134
return Err(ArenaError::AliasingPairAccess);
@@ -146,7 +143,7 @@ impl<T> StableVec<T> {
146143
unsafe {
147144
let pa = self.buckets[ba].unwrap_unchecked().as_ptr().add(sa);
148145
let pb = self.buckets[bb].unwrap_unchecked().as_ptr().add(sb);
149-
Ok((&mut *pa, &mut *pb))
146+
Ok([&mut *pa, &mut *pb])
150147
}
151148
}
152149

@@ -562,7 +559,7 @@ mod tests {
562559
#[test]
563560
fn get_pair_mut_disjoint() {
564561
let mut vector: StableVec<usize> = (0..100).collect();
565-
let (a, b) = vector.get_disjoint_mut([10, 90]).unwrap();
562+
let [a, b] = vector.get_disjoint_mut([10, 90]).unwrap();
566563
*a = 111;
567564
*b = 999;
568565
assert_eq!(vector.get(10), Some(&111));

0 commit comments

Comments
 (0)