Skip to content

[ER] Three Vec functions #82336

Closed
Closed
@leonardo-m

Description

@leonardo-m

Some member functions that could be added to Vec:

This is similar to Vec::remove but like Vec::pop it returns an Option, avoiding panics:

pub fn Vec::pop_index(&mut self, index: usize) -> Option<T>;

(In alternative Vec::pop_front could often suffice).


Probably this was already suggested elsewhere:

pub unsafe fn get_debug<I>(&self, index: I) -> &<I as SliceIndex<[T]>>::Output;
pub unsafe fn get_debug_mut<I>(&mut self, index: I) -> &mut <I as SliceIndex<[T]>>::Output;

They contain a debug_assert!() to test the bounds only in debug builds. I think such debug_assert can't be added to get_unchecked/get_unchecked_mut because the semantics is different. They are unsafe, but they add a bit of safety during debug runs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions