Conceptual
Login

Initialising a Structure in Place with pin-init

If a value may never move, you cannot build it on the stack and then move it into its box; it has to be constructed directly at its final address. The pin-init tooling does this: you annotate a structure, mark the fields that must not move, and write an initialiser expression that the macro turns into instructions for filling a freshly allocated, still-uninitialised allocation field by field. A fallible variant lets any field's initialisation return an error, and everything already built is correctly unwound. This is what lets a Rust driver embed locks and list nodes in its own state without a single hand-written pointer fix-up.

Questions this Concept answers

  • Why can a structure containing a kernel lock not be built on the stack and then moved into its allocation?