place 0.1.0

Placement new in Rust
Documentation
  • Coverage
  • 100%
    2 out of 2 items documented1 out of 1 items with examples
  • Size
  • Source code size: 4.12 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 500.63 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 8s Average build duration of successful builds.
  • all releases: 8s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • DianaNites

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() };