message: Minor cleanup changes to `SliceVec`
diff: @@ -16,7 +16,7 @@ use std::ops::Deref;
  /// - when pushing to multiple slices at once
  /// - when element initialization code has the possibility of failure
  pub struct SliceVec<'a, Elem> {
  - next_index: usize,
  + len: usize,
  // SAFETY: The slice `self.elems[..self.next_index]` should only ever
  // contain elements initialized with `MaybeUninit::new`.
  elems: &'a mut [MaybeUninit<Elem>],
  @@ -28,18 +28,34 @@ impl<'a, Elem> SliceVec<'a, Elem> {
  /// # Panics
  ///
  /// If the type has drop-glue to be executed.
  - pub fn new(scope: &'a scoped_arena::Scope<'a>, max_len: usize) -> SliceVec<'a, Elem> {
  + pub fn new(scope: &'a scoped_arena::Scope<'a>, capacity: usize) -> SliceVec<'a, Elem> {
  // NOTE: Ensure that that the element type does not have any drop glue.
  // This would be problematic as we have no way of registering the
  // drop glue of `Elem` with `scoped_arena::Scope`.
  assert!(!std::mem::needs_drop::<Elem>());
  SliceVec {
  - next_index: 0,
  - elems: scope.to_scope_many_with(max_len, MaybeUninit::uninit),
  + len: 0,
  + elems: scope.to_scope_many_with(capacity, MaybeUninit::uninit),
  }
  }
  + pub fn len(&self) -> usize {
  + self.len
  + }
  +
  + pub fn is_empty(&self) -> bool {
  + self.len() == 0
  + }
  +
  + pub fn capacity(&self) -> usize {
  + self.elems.len()
  + }
  +
  + pub fn is_full(&self) -> bool {
  + self.len() >= self.capacity()
  + }
  +
  /// Push an element to the slice builder.
  ///
  /// # Panics
  @@ -47,8 +63,14 @@ impl<'a, Elem> SliceVec<'a, Elem> {
  /// If the pushing the element would exceed the maximum slice length
  /// supplied in [`SliceBuilder::new`].
  pub fn push(&mut self, elem: Elem) {
  - self.elems[self.next_index] = MaybeUninit::new(elem);
  - self.next_index += 1;
  + if self.is_full() {
  + panic!(
  + "Cannot push onto a full `SliceVec` (capacity is {})",
  + self.capacity()
  + )
  + }
  + self.elems[self.len] = MaybeUninit::new(elem);
  + self.len += 1;
  }
  }
  @@ -64,7 +86,7 @@ impl<'a, Elem> Deref for SliceVec<'a, Elem> {
  // - `self.next_index` is only incremented in `SliceBuilder::push`, and in that
  // case we make sure `self.elems[self.next_index]` has been initialized before
  // hand.
  - unsafe { slice_assume_init_ref(&self.elems[..self.next_index]) }
  + unsafe { slice_assume_init_ref(&self.elems[..self.len]) }
  }
  }
  @@ -78,7 +100,7 @@ impl<'a, Elem> From<SliceVec<'a, Elem>> for &'a [Elem] {
  // - `self.next_index` is only incremented in `SliceBuilder::push`, and in that
  // case we make sure `self.elems[self.next_index]` has been initialized before
  // hand.
  - unsafe { slice_assume_init_ref(&slice.elems[..slice.next_index]) }
  + unsafe { slice_assume_init_ref(&slice.elems[..slice.len]) }
  }
  }
  