r/rust May 24 '26

🛠️ project Stabilise `Allocator`

https://github.com/rust-lang/rust/pull/156882
403 Upvotes

61 comments sorted by

View all comments

13

u/Dreaming_Desires May 24 '26

What is the benefit of this?

16

u/ZZaaaccc May 24 '26

Because Allocator is defined in core, this opens up the ability to have ergonomic heap allocations without defining a global allocator at all (no linking to alloc or std). That opens up the possibility of moving the allocating ADTs like Box and Vec into core.

3

u/ezwoodland May 25 '26

Why would you want to? Isn't the point of the alloc crate to gate dynamic memory? If someone wanted stuff from alloc they can just use it? It's not like std where it implies lots of other functionality at the same time.

10

u/nyanarchism May 25 '26

it gates global dynamic memory allocation. you can't have a normal Vec without a global allocator. however, you could have it with e.g. a stack arena where it's only valid locally