{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreih2pnkugm2sbjjvnkyvc44e72fnahnpaudlrh4owqrr57ev6zv5xa",
    "uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3mjl46vnpbw52"
  },
  "path": "/t/introduce-box-new-uninit-array-and-box-new-zeroed-array/24179#post_1",
  "publishedAt": "2026-04-15T22:47:01.000Z",
  "site": "https://internals.rust-lang.org",
  "textContent": "Currently the `Box` type has the methods `Box::new_uninit_slice(len: usize)` and `Box::new_zeroed_slice(len: usize)`, which create `Box<[MaybeUninit<T>]>` with uninitialized and zeroed memory respectively.\n\nI propose the creation of `Box::new_uninit_array()` and `Box::new_zeroed_array()`, which create `Box<[MaybeUninit<T>; N]>`, which create fixed-size arrays on the heap with a compile time size.\n\nOne example from my current use case (an I/O buffer):\n\n\n    struct Buffer<const N: usize> {\n        data: Box<[MaybeUninit<u8>; N]>,\n        ...\n    }\n\n    impl<const N: usize> Buffer<N> {\n        pub fn new() -> Self {\n            let data = Box::new_uninit_array();\n            ....\n\n            Self {\n                data,\n                ...\n            }\n        }\n    }\n\n\nTo my knowledge, the only way to do this currently is:\n\n\n    Box::new_uninit_slice(N).into_array().unwrap()\n\n\n...which is both unstable and somewhat unsightly in my opinion with an unwrap from an unnecessary runtime check.\n\nI would love to take a shot at making a PR myself, but I thought I should post here first before I did anything, I'm not sure of the exact process as this would be my first contribution to Rust. If anyone here has any objections or pointers please let me know.",
  "title": "Introduce `Box::new_uninit_array` and `Box::new_zeroed_array`"
}