Repository: tokio-rs/tokio
File: tokio/src/net/udp.rs (Rust)

Code before:
            self.io.registration().try_io(Interest::READABLE, || {
                let dst = buf.chunk_mut();
                let dst =
                    unsafe { &mut *(dst as *mut _ as *mut [std::mem::MaybeUninit<u8>] as *mut [u8]) };

                // Safety: We trust `UdpSocket::recv` to have filled up `n` bytes in the
                // buffer.
                let n = (*self.io).recv(dst)?;

                unsafe {
                    buf.advance_mut(n);
                }

                Ok(n)
            })
        }

        /// Receives a single datagram message on the socket from the remote address
        /// to which it is connected, advancing the buffer's internal cursor,
        /// returning how many bytes were read.
        ///
        /// The function must be called with valid byte array buf of sufficient size
        /// to hold the message bytes. If a message is too long to fit in the
        /// supplied buffer, excess bytes may be discarded.
        ///
        /// No byte array buf initialization is required.
        ///
        /// # Examples
        ///
        /// ```no_run
        /// use tokio::net::UdpSocket;
        /// use std::io;
        ///
        /// #[tokio::main]
        /// async fn main() -> io::Result<()> {
        ///     // Connect to a peer
        ///     let socket = UdpSocket::bind("127.0.0.1:8080").await?;
        ///     socket.connect("127.0.0.1:8081").await?;
        ///
        ///     let mut buf = Vec::with_capacity(512);
        ///     let len = socket.recv_buf(&mut buf).await?;
        ///
        ///     println!("received {} bytes {:?}", len, &buf[..len]);
        ///
        ///     Ok(())
        /// }
        /// ```
        pub async fn recv_buf<B: BufMut>(&self, buf: &mut B) -> io::Result<usize> {
            self.io.registration().async_io(Interest::READABLE, || {
                let dst = buf.chunk_mut();
                let dst =

Review comment (suggestion):
```suggestion
        /// This method can be used even if `buf` is uninitialized.
```

Code after:
            self.io.registration().try_io(Interest::READABLE, || {
                let dst = buf.chunk_mut();
                let dst =
                    unsafe { &mut *(dst as *mut _ as *mut [std::mem::MaybeUninit<u8>] as *mut [u8]) };

                let n = (*self.io).recv(dst)?;

                // Safety: We trust `UdpSocket::recv` to have filled up `n` bytes in the
                // buffer.
                unsafe {
                    buf.advance_mut(n);
                }

                Ok(n)
            })
        }

        /// Receives a single datagram message on the socket from the remote address
        /// to which it is connected, advancing the buffer's internal cursor,
        /// returning how many bytes were read.
        ///
        /// This method must be called with valid byte array buf of sufficient size
        /// to hold the message bytes. If a message is too long to fit in the
        /// supplied buffer, excess bytes may be discarded.
        ///
        /// This method can be used even if `buf` is uninitialized.
        ///
        /// # Examples
        ///
        /// ```no_run
        /// use tokio::net::UdpSocket;
        /// use std::io;
        ///
        /// #[tokio::main]
        /// async fn main() -> io::Result<()> {
        ///     // Connect to a peer
        ///     let socket = UdpSocket::bind("127.0.0.1:8080").await?;
        ///     socket.connect("127.0.0.1:8081").await?;
        ///
        ///     let mut buf = Vec::with_capacity(512);
        ///     let len = socket.recv_buf(&mut buf).await?;
        ///
        ///     println!("received {} bytes {:?}", len, &buf[..len]);
        ///
        ///     Ok(())
        /// }
        /// ```
        pub async fn recv_buf<B: BufMut>(&self, buf: &mut B) -> io::Result<usize> {
            self.io.registration().async_io(Interest::READABLE, || {
                let dst = buf.chunk_mut();
                let dst =