]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #89123 - the8472:push_in_capacity, r=amanieu
authorbors <bors@rust-lang.org>
Sun, 9 Oct 2022 21:02:33 +0000 (21:02 +0000)
committerbors <bors@rust-lang.org>
Sun, 9 Oct 2022 21:02:33 +0000 (21:02 +0000)
add Vec::push_within_capacity - fallible, does not allocate

This method can serve several purposes. It

* is fallible
* guarantees that items in Vec aren't moved
* allows loops that do `reserve` and `push` separately to avoid pulling in the allocation machinery a second time in the `push` part which should make things easier on the optimizer
* eases the path towards `ArrayVec` a bit since - compared to `push()` - there are fewer questions around how it should be implemented

I haven't named it `try_push` because that should probably occupy a middle ground that will still try to reserve and only return an error in the unlikely OOM case.

resolves #84649

1  2 
library/alloc/src/vec/mod.rs

Simple merge