Is there any way to use collections on the stack in Rust?

Is there any way to use collections from the standard rust library on the stack? Suppose you know in advance the upper bound on the number of elements that you want to keep in a collection.

+5
source share
1 answer

If you look at the Vec implementation (admittedly one of the simplest collections), you will notice:

 use alloc::heap::{EMPTY, allocate, reallocate, deallocate}; 

Unlike C ++, collections are not yet parameterized by the allocator. This is certainly desirable in the long run, but it was not considered necessary for 1.0.

If I remember the discussion correctly, some suggestions depended on HKT (higher types), but that wasnโ€™t all.

So, not yet.

+6
source

Source: https://habr.com/ru/post/1209237/


All Articles