Rust 1.61.0 released
Rust 1.61.0 released
Posted May 24, 2022 15:25 UTC (Tue) by mathstuf (subscriber, #69389)In reply to: Rust 1.61.0 released by Wol
Parent article: Rust 1.61.0 released
The default is to put things on the stack. Or do you mean being able to do something like `[u8; some_local_size]`? I don't think that's possible (the size must be constant evaluated). I think the closest you can get is:
```
let mut _buf = [u8; MAX_SIZE]; // Don't use directly.
let buf = &mut _buf[0..local_size]; // Get a local view into the buffer.
```
But this will always use the maximum size. Note that there are likely perf issues when using something like this that has an `impl Drop` (though maybe `Option<T>` assuming it doesn't take up more room could help elide things there?).
Or course, there is always the possibility that there is some solution that I haven't come across.