Skip to content

Add push_mut, insert_mut, etc. #302

Description

@survived

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions