I am experimenting with the usage of const-fn to precompute few things in my code, and the results are good enough. This is an example of computing a small table of primes below 1000 (it computes the primes two times, the first time counts them in the interval, and then uses that result to define a fixed-size array, so it's a two phase computation):

```
const fn count_primes<const LIMIT: usize>() -> usize {
let mut is_prime = [true; LIMIT];
let mut count = 0;
...
count
}
const fn primes_array<const LEN: usize>() -> [u32; LEN] {
let mut result = [0; LEN];
...
result
}
const PRIMES: [u32; count_primes::<1000>()] = primes_array();
```

But in similar situations I'd like a way to allocate on the heap in a const-fn and then convert the heap data structure into fixed size data structure. With some limitations this is possible in D language:

```
int[] foo(uint n)() {
return new int[n];
}
// Implicit cast from compile-time heap to fixed size array:
enum int[5] DATA = foo!(5)();
void main() {}
```

You can even do this if you want:

```
int[] foo(uint n)() {
return new int[n];
}
enum int[] DATA = foo!(5)();
enum uint LEN = DATA.length;
enum int[LEN] DATA2 = DATA;
void main() {}
```

Rust language is thankfully more principled, and you need to be more principled if you want to do something like that for arbitrary data structures (like a HashMap).

A solutions is to introduce a freezing function that returns a different immutable heap-allocated data struture (that lacks mutating accessors).