Skip to content

Implement Fill for [MaybeUninit<T>] #1080

Closed
@kangalio

Description

@kangalio

Background

What is your motivation? Right now, the Rng::fill function can only write to buffers that are already initialized. That's because passing uninitialized memory as a &[T] is undefined behavior. With an AsByteSliceMut implementation for [MaybeUninit<T>], rand could be used to write vast amounts of random numbers into memory without needing to zero out the memory before.

What type of application is this? Fast generation of vast amounts of numbers

Feature request

The rand::AsByteSliceMut trait should be implemented for all [MaybeUninit<T>] where T are the numeric integer types. In other words, similar to how you can fill a &mut [u32]/&mut [i32]/&mut [usize]/... or a &mut [Wrapping<u32>]/&mut [Wrapping<i32>]/&mut [Wrapping<usize>]/..., rand should support filling a &mut [MaybeUninit<u32>]/&mut [MaybeUninit<i32>]/&mut [MaybeUninit<usize>]/...

Metadata

Metadata

Assignees

No one assigned

    Labels

    P-postponeWaiting on something else

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions