Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 4e4940e

Browse files
committed
Add Arena::alloc_many to easily get IdxRange
There are no currently ways to get `IdxRange` without manually offseting `Idx`. Providing a method for multiple-allocation simplifies this process and makes it less error-prone.
1 parent 300f3a1 commit 4e4940e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

lib/la-arena/src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,21 @@ impl<T> Arena<T> {
312312
idx
313313
}
314314

315+
/// Densely allocates multiple values, returning the values’ index range.
316+
///
317+
/// ```
318+
/// let mut arena = la_arena::Arena::new();
319+
/// let range = arena.alloc_many(0..4);
320+
///
321+
/// assert_eq!(arena[range], [0, 1, 2, 3]);
322+
/// ```
323+
pub fn alloc_many<II: IntoIterator<Item = T>>(&mut self, iter: II) -> IdxRange<T> {
324+
let start = self.next_idx();
325+
self.extend(iter);
326+
let end = self.next_idx();
327+
IdxRange::new(start..end)
328+
}
329+
315330
/// Returns an iterator over the arena’s elements.
316331
///
317332
/// ```

0 commit comments

Comments
 (0)