pub trait UninitSyncReadExt: UninitRead + Read {
// Provided methods
fn read_uninit<'buf>(
&mut self,
buf: &'buf mut [MaybeUninit<u8>],
) -> Result<&'buf [u8], Error> { ... }
fn read_uninit_exact<'buf>(
&mut self,
buf: &'buf mut [MaybeUninit<u8>],
) -> Result<&'buf [u8], Error> { ... }
}Expand description
An extension trait that provides convenience methods for synchronous readers
that implement UninitRead.
This trait is automatically implemented for any type that satisfies the bounds
Read + UninitRead. It offers safe wrappers for reading directly into
uninitialized buffers, abstracting away the underlying unsafe operations.
Provided Methods§
Sourcefn read_uninit<'buf>(
&mut self,
buf: &'buf mut [MaybeUninit<u8>],
) -> Result<&'buf [u8], Error>
fn read_uninit<'buf>( &mut self, buf: &'buf mut [MaybeUninit<u8>], ) -> Result<&'buf [u8], Error>
Pulls some bytes from this source into the provided uninitialized buffer.
This method is a wrapper around Read::read that accepts a slice of
MaybeUninit<u8>, avoiding the need for the caller to perform unsafe
operations.
On a successful read, this method returns a slice &[u8] that represents the
portion of the buffer that was initialized by the read. The length of the
returned slice is equivalent to the number of bytes read. An empty slice indicates
EOF has been reached.
§Errors
This function will return an error if the underlying call to Read::read
returns an error.
Sourcefn read_uninit_exact<'buf>(
&mut self,
buf: &'buf mut [MaybeUninit<u8>],
) -> Result<&'buf [u8], Error>
fn read_uninit_exact<'buf>( &mut self, buf: &'buf mut [MaybeUninit<u8>], ) -> Result<&'buf [u8], Error>
Reads the exact number of bytes required to fill buf from this source.
This method is a wrapper around Read::read_exact that accepts a slice of
MaybeUninit<u8>, avoiding the need for the caller to perform unsafe
operations.
On a successful read, this method returns a slice &[u8] that represents the
entire buffer, now guaranteed to be fully initialized.
§Errors
This function will return an error if the underlying call to Read::read_exact
returns an error. If an EOF is found before the buffer is filled, an error
of kind std::io::ErrorKind::UnexpectedEof is returned.