diff options
| author | Yuki Okushi <huyuumi.dev@gmail.com> | 2019-11-08 13:42:14 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-11-08 13:42:14 +0900 |
| commit | a00c777b75f67812207e5737f3093cd3d7cdf7de (patch) | |
| tree | 160ff19f291c0c04886c585ad2f04f8cccbf4e05 /src/test/debuginfo/enum-thinlto.rs | |
| parent | 32aa327ba35c4b0f95c7c4cd983f1867fc498897 (diff) | |
| parent | 639c4f779c60119383dd8a49b44522f6a6958a53 (diff) | |
| download | rust-a00c777b75f67812207e5737f3093cd3d7cdf7de.tar.gz rust-a00c777b75f67812207e5737f3093cd3d7cdf7de.zip | |
Rollup merge of #65580 - SimonSapin:maybeuninit-array, r=Amanieu
Add `MaybeUninit` methods `uninit_array`, `slice_get_ref`, `slice_get_mut`
Eventually these will hopefully become the idiomatic way to work with partially-initialized stack buffers.
All methods are unstable. Note that `uninit_array` takes a type-level `const usize` parameter, so it is blocked (at least in its current form) on const generics.
Example:
```rust
use std::mem::MaybeUninit;
let input = b"Foo";
let f = u8::to_ascii_uppercase;
let mut buffer: [MaybeUninit<u8>; 32] = MaybeUninit::uninit_array();
let vec;
let output = if let Some(buffer) = buffer.get_mut(..input.len()) {
buffer.iter_mut().zip(input).for_each(|(a, b)| { a.write(f(b)); });
unsafe { MaybeUninit::slice_get_ref(buffer) }
} else {
vec = input.iter().map(f).collect::<Vec<u8>>();
&vec
};
assert_eq!(output, b"FOO");
```
Diffstat (limited to 'src/test/debuginfo/enum-thinlto.rs')
0 files changed, 0 insertions, 0 deletions
