← Back to context

Comment by zozbot234

3 years ago

User-specified local allocators are planned for Rust too. Among other things, they're needed for feature parity with C++.

Technically it’s only the standard library that lacks custom allocator support. Box and Vec and all the rest are “just” types defined in the standard library, and if you define your own, you can use any allocator you want and still take advantage of the borrow checker and other language features. This has been possible since 1.0.

…Well, except for certain magic features that the standard library types get that you can’t (yet) replicate in a custom type. This is an annoying wart, but they’re relatively minor.

But yeah, custom allocator support for standard library containers is planned.

I recommend taking a look at Cone in a little more detail, its type system support for allocators are head and shoulders above what Rust has. The language's awareness of allocator allows it to decouple it from the users code in a way no other language allows (except perhaps Odin).

>"feature parity with C++"

I think Rust is missing a fair bit more than "user-specified local allocators" to be on feature parity with C++. Curious if it plans to be on full feature parity.

  • It definitely misses some features that are considered bad: e.g implementation inheritance or memory handling by exceptions. Those are not essential for anything and are not planned.

    • >" implementation inheritance "

      What authority declares implementation inheritance bad may I ask? As long as one does not stick it into inappropriate places it is actually very helpful.

      4 replies →