]> git.lizzy.rs Git - rust.git/commit
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)
commit1a7c203e7f89f92598a793c6f6406735c024e7ee
tree092e5362232165047754ef24ff91a0a242790bbf
parent81f391930301afbc121b7c468138069daa354bf8
parentbb74f97445f04d68e42e7e308a109f78a2d2b0f7
Auto merge of #89123 - the8472:push_in_capacity, r=amanieu

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
library/alloc/src/vec/mod.rs