Initialization in Rust with pin-init
summary
Rust code in the kernel uses pin-init to perform safe, ergonomic in-place initialization of address-sensitive types, avoiding 1MB stack overflows by returning initializers (effectively closures) that run later. The crate supports pinned and normal initializers, error-aware allocation with ? and automatic rollback on failure, pin projections via a proc macro, and ad-hoc init blocks. Work is ongoing to standardize in-place initialization as a language feature and vendor the crate in the kernel.
AI-written summary · about
chapters (10)
- 0:00Why initialization is hard
- 3:54Outpointers in C vs Rust
- 7:25Introducing pin-init
- 13:26Pinning and initialization traits
- 17:41Raw pointers vs references
- 21:35Structural pinning explained
- 25:29When initialization happens
- 27:33Error handling in initializers
- 32:28New features in pin-init
- 35:57Future of in-place initialization
related talks
26mpin-init: Solving Address Stability in Rust
11mLightning talk: Manual (de)initialization A Rust and C++
31mGetting Something for Nothing
24mMove Constructors: Is it Possible?
47mRust project goals 2024: Stabilizing Rust in the Linux Kernel
25mIntro and Overview to Rust
40mRust’s approach of getting things right
23mDealing with Uninitialized Memory in the Kernel
