4 ms·
As I wrote in https://news.ycombinator.com/item?id=44048391 https://news.ycombinator.com/item?id=44048391 , you have to get used to copying the libstd impl when
by Arnavion 1y ago
As I wrote in https://news.ycombinator.com/item?id=44048391 https://news.ycombinator.com/item?id=44048391 , you have to get used to copying the libstd impl when working with MaybeUninit. For my code I put a "TODO(rustup)" comment on such copies, to remind myself to revisit them every time I update the Rust version in toolchain.toml
- nemothekid 1y agoIn other words the """safe""" stable code looks like this: let mut data = Vec::with_capacity(sz); let mut dst_uninit = data.spare_capacity_mut(); let uninit_src: &[MaybeUninit<T>] = unsafe { transmute(buf) }; dst_uninit.copy_from_slice(uninit_src); unsafe { data.set_len(sz) };
- Arnavion 1y agoThat's correct.