Crates.io | place |
lib.rs | place |
version | 0.1.0 |
source | src |
created_at | 2022-04-15 14:18:47.66048 |
updated_at | 2022-05-05 16:25:56.265293 |
description | Placement new in Rust |
homepage | |
repository | |
max_upload_size | |
id | 568479 |
size | 4,447 |
Placement new in Rust
A simple wrapper around MaybeUninit
that allows one to simply and safely
initialize a struct field-by-field
use place::place;
use std::mem::MaybeUninit;
struct MyCoolStruct {
b: bool,
u: u32,
}
let mut buf = MaybeUninit::uninit();
let x: &mut MyCoolStruct = place!(
buf,
MyCoolStruct {
b: true,
u: 69420,
}
);
// SAFETY: buf has been initialized above
unsafe { buf.assume_init_drop() };