Conceptual
Login

Uninitialized Memory and How Rust Handles It

Rust normally refuses to let you read a value that has not been set, because whatever bits are there are meaningless. Sometimes you genuinely have a block of memory that something else will fill — hardware, or C code — so Rust gives you a wrapper that says "this may not be a valid value yet" and makes you assert when it finally is. It keeps the dangerous window explicit and short.

Questions this Concept answers

  • Why is reading uninitialized memory undefined behaviour rather than merely returning junk?