{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreibpqq4e5dpp6inyaaqd2ykqtc4y4gsrvyqvrak6eapycyuj42sz2q",
"uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3mmhd4aahmjg2"
},
"path": "/t/another-experiment-to-make-unsafe-rust-safer-preventing-ub-in-maybeuninit-with-compile-time-error/24352#post_6",
"publishedAt": "2026-05-22T15:28:49.000Z",
"site": "https://internals.rust-lang.org",
"textContent": "`MaybeUninit<T>` is a `union` (a tagless `enum`) between a dataless variant called `uninit` and a variant with `T` data called `value`.\n\n`Option<T>` is an `enum` between a dataless variant called `None` and a variant with `T` data called `Some`.\n\nIn other words, (ignoring optimizations and focusing on semantics,) `Option<T>` is very similar to a `(bool, MaybeUninit<T>)` pair, where the boolean tag indicates whether the second field is initialized. The initialization is checked at runtime instead of compile time.\n\nWith typestate, you have two separate types, one which is dataless and one which has `T` data. This is already possible with `()` and `T` respectively, even if wrappers around `MaybeUninit<T>` could serve the same purpose.\n\nIncremental initialization could be interesting.",
"title": "Another Experiment To Make Unsafe Rust Safer: Preventing UB In MaybeUninit With Compile Time Error"
}