pub struct IovIterSource<'data> { /* private fields */ }
Expand description
An IO vector that acts as a source of data.
The data may come from many different sources. This includes both things in kernel-space and
reading from userspace. It’s not necessarily the case that the data source is immutable, so
rewinding the IO vector to read the same data twice is not guaranteed to result in the same
bytes. It’s also possible that the data source is mapped in a thread-local manner using e.g.
kmap_local_page()
, so this type is not Send
to ensure that the mapping is read from the
right context in that scenario.
§Invariants
Must hold a valid struct iov_iter
with data_source
set to ITER_SOURCE
. For the duration
of 'data
, it must be safe to read from this IO vector using the standard C methods for this
purpose.
Implementations§
Source§impl<'data> IovIterSource<'data>
impl<'data> IovIterSource<'data>
Sourcepub unsafe fn from_raw<'iov>(
ptr: *mut iov_iter,
) -> &'iov mut IovIterSource<'data>
pub unsafe fn from_raw<'iov>( ptr: *mut iov_iter, ) -> &'iov mut IovIterSource<'data>
Obtain an IovIterSource
from a raw pointer.
§Safety
- The referenced
struct iov_iter
must be valid and must only be accessed through the returned reference for the duration of'iov
. - The referenced
struct iov_iter
must havedata_source
set toITER_SOURCE
. - For the duration of
'data
, it must be safe to read from this IO vector using the standard C methods for this purpose.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of bytes available in this IO vector.
Note that this may overestimate the number of bytes. For example, reading from userspace
memory could fail with EFAULT
, which will be treated as the end of the IO vector.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns whether there are any bytes left in this IO vector.
This may return true
even if there are no more bytes available. For example, reading from
userspace memory could fail with EFAULT
, which will be treated as the end of the IO vector.
Sourcepub fn advance(&mut self, bytes: usize)
pub fn advance(&mut self, bytes: usize)
Advance this IO vector by bytes
bytes.
If bytes
is larger than the size of this IO vector, it is advanced to the end.
Sourcepub unsafe fn revert(&mut self, bytes: usize)
pub unsafe fn revert(&mut self, bytes: usize)
Advance this IO vector backwards by bytes
bytes.
§Safety
The IO vector must not be reverted to before its beginning.
Sourcepub fn copy_from_iter(&mut self, out: &mut [u8]) -> usize
pub fn copy_from_iter(&mut self, out: &mut [u8]) -> usize
Read data from this IO vector.
Returns the number of bytes that have been copied.
Sourcepub fn copy_from_iter_vec<A: Allocator>(
&mut self,
out: &mut Vec<u8, A>,
flags: Flags,
) -> Result<usize>
pub fn copy_from_iter_vec<A: Allocator>( &mut self, out: &mut Vec<u8, A>, flags: Flags, ) -> Result<usize>
Read data from this IO vector and append it to a vector.
Returns the number of bytes that have been copied.
Sourcepub fn copy_from_iter_raw(&mut self, out: &mut [MaybeUninit<u8>]) -> &mut [u8]
pub fn copy_from_iter_raw(&mut self, out: &mut [MaybeUninit<u8>]) -> &mut [u8]
Read data from this IO vector into potentially uninitialized memory.
Returns the sub-slice of the output that has been initialized. If the returned slice is shorter than the input buffer, then the entire IO vector has been read.
This will never write uninitialized bytes to the provided buffer.
Auto Trait Implementations§
impl<'data> !Freeze for IovIterSource<'data>
impl<'data> !RefUnwindSafe for IovIterSource<'data>
impl<'data> !Send for IovIterSource<'data>
impl<'data> !Sync for IovIterSource<'data>
impl<'data> !Unpin for IovIterSource<'data>
impl<'data> UnwindSafe for IovIterSource<'data>
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