place

Crates.ioplace
lib.rsplace
version0.1.0
sourcesrc
created_at2022-04-15 14:18:47.66048
updated_at2022-05-05 16:25:56.265293
descriptionPlacement new in Rust
homepage
repository
max_upload_size
id568479
size4,447
Diana (DianaNites)

documentation

README

Place

Placement new in Rust

A simple wrapper around MaybeUninit that allows one to simply and safely initialize a struct field-by-field

Usage

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() };
Commit count: 0

cargo fmt