rust/library/alloc/tests
Guillaume Boisseau e3c0158788
Rollup merge of #120504 - kornelski:try_with_capacity, r=Amanieu
Vec::try_with_capacity

Related to #91913

Implements try_with_capacity for `Vec`, `VecDeque`, and `String`. I can follow it up with more collections if desired.

`Vec::try_with_capacity()` is functionally equivalent to the current stable:

```rust
let mut v = Vec::new();
v.try_reserve_exact(n)?
```

However, `try_reserve` calls non-inlined `finish_grow`, which requires old and new `Layout`, and is designed to reallocate memory. There is benefit to using `try_with_capacity`, besides syntax convenience, because it generates much smaller code at the call site with a direct call to the allocator. There's codegen test included.

It's also a very desirable functionality for users of `no_global_oom_handling` (Rust-for-Linux), since it makes a very commonly used function available in that environment (`with_capacity` is used much more frequently than all `(try_)reserve(_exact)`).
2024-03-09 21:40:06 +01:00
..
arc.rs remove redundant imports 2023-12-10 10:56:22 +08:00
autotraits.rs apply fmt 2024-01-11 15:04:48 +03:00
borrow.rs remove redundant imports 2023-12-10 10:56:22 +08:00
boxed.rs rm const traits in libcore 2023-04-16 06:49:27 +00:00
btree_set_hash.rs Include the length in BTree hashes 2021-10-01 12:29:09 -07:00
c_str.rs Remove use of reverted std::ffi::c_char 2022-04-27 14:01:04 -07:00
const_fns.rs fix library and rustdoc tests 2023-04-16 11:38:52 +00:00
cow_str.rs mv std libs to library/ 2020-07-27 19:51:13 -05:00
fmt.rs rename ptr::invalid -> ptr::without_provenance 2024-02-21 20:15:52 +01:00
heap.rs Rename AllocRef to Allocator and (de)alloc to (de)allocate 2020-12-04 14:47:15 +01:00
lib.rs Rollup merge of #120504 - kornelski:try_with_capacity, r=Amanieu 2024-03-09 21:40:06 +01:00
linked_list.rs Classify BinaryHeap & LinkedList unit tests as such 2022-03-11 11:33:59 +01:00
rc.rs remove redundant imports 2023-12-10 10:56:22 +08:00
slice.rs Stabilize slice_group_by 2023-11-07 17:46:00 +01:00
str.rs optimize str::iter::Chars::advance_by 2023-11-27 22:06:35 +01:00
string.rs try_with_capacity for Vec, VecDeque, String 2024-03-01 18:24:02 +00:00
task.rs will_wake tests fail on Miri and that is expected 2024-03-05 09:33:55 +01:00
thin_box.rs Make use of pointer::is_aligned[_to] 2022-08-21 15:46:03 +04:00
vec_deque.rs try_with_capacity for Vec, VecDeque, String 2024-03-01 18:24:02 +00:00
vec.rs try_with_capacity for Vec, VecDeque, String 2024-03-01 18:24:02 +00:00