heapless icon indicating copy to clipboard operation
heapless copied to clipboard

feature: initialize with const

Open oligamiq opened this issue 1 year ago • 4 comments

When creating a vec, is it possible to use const fn so that the values can be prepared from the beginning?

oligamiq avatar Oct 09 '24 05:10 oligamiq

Only in nightly Rust for now.

burrbull avatar Oct 09 '24 05:10 burrbull

Do you plan to achieve an equivalent in stable using macros?

oligamiq avatar Oct 09 '24 05:10 oligamiq

Couldn't the for loop in Vec::from_array be replaced with ptr::copy_nonoverlapping::<T>(ptr::from_ref(&src).cast(), v.buffer.as_mut_ptr().cast(), M)? Then it could be const on 1.83.

Then it would be useful to mark String::from_utf8_unchecked const.

wetheredge avatar Jan 01 '25 20:01 wetheredge

I think discussion can be more alive if you form your suggestion into PR.

burrbull avatar Jan 01 '25 22:01 burrbull