Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impl From for &mut UninitSlice to &mut [MaybeUninit<u8>] #548

Merged
merged 1 commit into from
May 10, 2022

Commits on May 9, 2022

  1. Add UninitSlice::as_uninit_slice_mut()

    This adds an unsafe method to convert a `&mut UninitSlice` into a
    `&mut [MaybeUninit<u8>]`. This method is unsafe because some of the
    bytes in the slice may be initialized, and the caller should not
    overwrite them with uninitialized bytes.
    
    This came about when auditing [tokio-util's udp frame], where they want
    to pass the unitialized portion of a `BytesMut` to [ReadBuf::uninit].
    They need to do this unsafe pointer casting in a few places, which
    complicates audits. This method lets us document the safety invariants
    the caller needs to maintain when doing this conversion.
    
    [tokio-util's udp frame]: https:/tokio-rs/tokio/blob/master/tokio-util/src/udp/frame.rs#L87
    [ReadBuf::uninit]: https://docs.rs/tokio/latest/tokio/io/struct.ReadBuf.html#method.uninit
    erickt committed May 9, 2022
    Configuration menu
    Copy the full SHA
    0dbe185 View commit details
    Browse the repository at this point in the history