Skip to content

inplace-init

Initialize in place. Pin only when the address matters.

inplace-init is a no_std-friendly Rust library for constructing a value in caller-provided storage. Initializers can write a complete value or build a struct one field at a time. A receipt keeps exclusive access to the result and is responsible for dropping it.

Use the movable APIs for ordinary values. Use the pinned APIs when construction needs the value’s final address, such as for a self-referential type. The derive and initializer macros generate the field projection and type-state plumbing.

Start with a working example

Follow the getting started guide to initialize a struct with init! and init_in.

Build with a derive

Use #[derive(Init)] for a type-state builder and per-field defaults.

  • InitSlot represents one exclusive, uninitialized destination.
  • Successful initialization returns an InitReceipt that owns the value’s destruction responsibility.
  • Generated struct initializers project fields into the final destination and clean up already initialized fields if a later field fails.
  • Pinned initialization uses a separate mode and receipt API so a value can be built at its final address and accessed through Pin.

The default feature set is no_std and does not enable allocation. Enable alloc for boxed initialization and allocation-backed collection defaults; enable std for HashMap and HashSet defaults.