pub struct UserSliceReader { /* private fields */ }
Expand description
A reader for UserSlice
.
Used to incrementally read from the user slice.
Implementations§
Source§impl UserSliceReader
impl UserSliceReader
Sourcepub fn skip(&mut self, num_skip: usize) -> Result
pub fn skip(&mut self, num_skip: usize) -> Result
Skip the provided number of bytes.
Returns an error if skipping more than the length of the buffer.
Sourcepub fn clone_reader(&self) -> UserSliceReader
pub fn clone_reader(&self) -> UserSliceReader
Create a reader that can access the same range of data.
Reading from the clone does not advance the current reader.
The caller should take care to not introduce TOCTOU issues, as described in the
documentation for UserSlice
.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of bytes left to be read from this reader.
Note that even reading less than this number of bytes may fail.
Sourcepub fn read_raw(&mut self, out: &mut [MaybeUninit<u8>]) -> Result
pub fn read_raw(&mut self, out: &mut [MaybeUninit<u8>]) -> Result
Reads raw data from the user slice into a kernel buffer.
For a version that uses &mut [u8]
, please see UserSliceReader::read_slice
.
Fails with EFAULT
if the read happens on a bad address, or if the read goes out of
bounds of this UserSliceReader
. This call may modify out
even if it returns an error.
§Guarantees
After a successful call to this method, all bytes in out
are initialized.
Sourcepub fn read_slice(&mut self, out: &mut [u8]) -> Result
pub fn read_slice(&mut self, out: &mut [u8]) -> Result
Reads raw data from the user slice into a kernel buffer.
Fails with EFAULT
if the read happens on a bad address, or if the read goes out of
bounds of this UserSliceReader
. This call may modify out
even if it returns an error.
Sourcepub fn read<T: FromBytes>(&mut self) -> Result<T>
pub fn read<T: FromBytes>(&mut self) -> Result<T>
Reads a value of the specified type.
Fails with EFAULT
if the read happens on a bad address, or if the read goes out of
bounds of this UserSliceReader
.
Sourcepub fn read_all<A: Allocator>(
self,
buf: &mut Vec<u8, A>,
flags: Flags,
) -> Result
pub fn read_all<A: Allocator>( self, buf: &mut Vec<u8, A>, flags: Flags, ) -> Result
Reads the entirety of the user slice, appending it to the end of the provided buffer.
Fails with EFAULT
if the read happens on a bad address.
Sourcepub fn strcpy_into_buf<'buf>(self, buf: &'buf mut [u8]) -> Result<&'buf CStr>
pub fn strcpy_into_buf<'buf>(self, buf: &'buf mut [u8]) -> Result<&'buf CStr>
Read a NUL-terminated string from userspace and return it.
The string is read into buf
and a NUL-terminator is added if the end of buf
is reached.
Since there must be space to add a NUL-terminator, the buffer must not be empty. The
returned &CStr
points into buf
.
Fails with EFAULT
if the read happens on a bad address (some data may have been
copied).
Auto Trait Implementations§
impl Freeze for UserSliceReader
impl RefUnwindSafe for UserSliceReader
impl !Send for UserSliceReader
impl !Sync for UserSliceReader
impl Unpin for UserSliceReader
impl UnwindSafe for UserSliceReader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> PinInit<T> for T
impl<T> PinInit<T> for T
Source§unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>
unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>
slot
. Read more