Proposed new methods:
impl<T, const CAP: usize> ArrayVec<T, CAP> {
pub fn push_mut(&mut self, element: T) -> &mut T { /* … */ }
pub fn try_push_mut(&mut self, element: T) -> Result<&mut T, CapacityError<T>> { /* … */ }
pub fn insert_mut(&mut self, index: usize, element: T) -> &mut T { /* … */ }
pub fn try_insert_mut(&mut self, index: usize, element: T) -> Result<&mut T, CapacityError<T>> { /* … */ }
}
These methods add a way to get back a reference to the just-inserted value, and eliminate having tounwrap when we need access the value after it was inserted.
This would be aligned to methods that are being added to Rust standard Vec, currently only available only in nightly, see Vec::push_mut and Vec::insert_mut
Proposed new methods:
These methods add a way to get back a reference to the just-inserted value, and eliminate having to
unwrapwhen we need access the value after it was inserted.This would be aligned to methods that are being added to Rust standard
Vec, currently only available only in nightly, seeVec::push_mutandVec::insert_mut