pub struct IoVector<'a> {
vector: Vec<IoSlice<'a>>,
total_size: u64,
}
Expand description
Vector of memory buffers.
Fields§
§vector: Vec<IoSlice<'a>>
Buffer list.
total_size: u64
Complete size in bytes.
Implementations§
Source§impl<'a> IoVector<'a>
impl<'a> IoVector<'a>
Sourcepub fn with_capacity(cap: usize) -> Self
pub fn with_capacity(cap: usize) -> Self
Create an empty vector, pre-allocating space for cap
buffers.
This does not allocate an memory buffer, only space in the buffer vector.
Sourcepub fn push_ioslice(&mut self, ioslice: IoSlice<'a>)
pub fn push_ioslice(&mut self, ioslice: IoSlice<'a>)
Append a slice.
Sourcepub fn insert(&mut self, index: usize, slice: &'a [u8])
pub fn insert(&mut self, index: usize, slice: &'a [u8])
Insert a slice at the given index
in the buffer vector.
Sourcepub fn buffer_count(&self) -> usize
pub fn buffer_count(&self) -> usize
Return the number of buffers in this vector.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Return true
if and only if this vector’s length is zero.
Synonymous with whether this vector’s buffer count is zero.
Sourcepub fn append(&mut self, other: Self)
pub fn append(&mut self, other: Self)
Append all buffers from the given other vector to this vector.
Sourcepub fn split_at(self, mid: u64) -> (Self, Self)
pub fn split_at(self, mid: u64) -> (Self, Self)
Split the vector into two.
The first returned vector contains the bytes in the [..mid]
range, and the second
one covers the [mid..]
range.
Sourcepub fn split_tail_at(self, mid: u64) -> Self
pub fn split_tail_at(self, mid: u64) -> Self
Like Self::split_at()
, but discards the head, only returning the tail.
More efficient than to use self.split_at(mid).1
because the former requires
creating a new Vec
object for the head, which this version skips.
Sourcepub fn copy_into_slice(&self, slice: &mut [u8])
pub fn copy_into_slice(&self, slice: &mut [u8])
Copy the data from self
into slice
.
Both must have the same length.
Sourcepub fn try_into_owned(self, alignment: usize) -> Result<IoBuffer>
pub fn try_into_owned(self, alignment: usize) -> Result<IoBuffer>
Create a single owned IoBuffer
with the same data (copied).
Sourcepub unsafe fn as_iovec<'b>(&'b self) -> &'b [iovec]where
Self: 'b,
pub unsafe fn as_iovec<'b>(&'b self) -> &'b [iovec]where
Self: 'b,
Return a corresponding &[libc::iovec]
.
§Safety
iovec
has no lifetime information. Callers must ensure no elements in the
returned slice are used beyond the lifetime '_
.
Sourcepub fn is_aligned(&self, mem_alignment: usize, req_alignment: usize) -> bool
pub fn is_aligned(&self, mem_alignment: usize, req_alignment: usize) -> bool
Check whether self
is aligned.
Each buffer must be aligned to mem_alignment
, and each buffer’s length must be
aligned to both mem_alignment
and req_alignment
(the I/O request offset/size
alignment).
Sourcepub fn into_inner(self) -> Vec<IoSlice<'a>>
pub fn into_inner(self) -> Vec<IoSlice<'a>>
Return the internal vector of IoSlice
objects.
Sourcepub fn with_pushed<'b>(self, slice: &'b [u8]) -> IoVector<'b>where
'a: 'b,
pub fn with_pushed<'b>(self, slice: &'b [u8]) -> IoVector<'b>where
'a: 'b,
Same as Self::push()
, but takes ownership of self
.
By taking ownership of self
and returning it, this method allows reducing the
lifetime of self
to that of slice
, if necessary.
Sourcepub fn with_inserted<'b>(self, index: usize, slice: &'b [u8]) -> IoVector<'b>where
'a: 'b,
pub fn with_inserted<'b>(self, index: usize, slice: &'b [u8]) -> IoVector<'b>where
'a: 'b,
Same as Self::insert()
, but takes ownership of self.
By taking ownership of self
and returning it, this method allows reducing the
lifetime of self
to that of slice
, if necessary.
Sourcefn do_split_at(
self,
mid: u64,
keep_head: bool,
) -> (Option<IoVector<'a>>, IoVector<'a>)
fn do_split_at( self, mid: u64, keep_head: bool, ) -> (Option<IoVector<'a>>, IoVector<'a>)
Implementation for Self::split_at()
and Self::split_tail_at()
.
If keep_head
is true, both head and tail are returned (Self::split_at()
).
Otherwise, the head is discarded (Self::split_tail_at()
).
Source§impl<'a> IoVector<'a>
impl<'a> IoVector<'a>
Sourcepub fn from_volatile_slice<B: BitmapSlice, I: IntoIterator<Item: ImagoAsRef<'a, VolatileSlice<'a, B>>, IntoIter: ExactSizeIterator>>(
slices: I,
) -> (Self, VolatileSliceGuard<'a, PtrGuard, B>)
pub fn from_volatile_slice<B: BitmapSlice, I: IntoIterator<Item: ImagoAsRef<'a, VolatileSlice<'a, B>>, IntoIter: ExactSizeIterator>>( slices: I, ) -> (Self, VolatileSliceGuard<'a, PtrGuard, B>)
Converts a VolatileSlice
array (from vm-memory) into an IoVector
.
In addition to a the vector, return a guard that ensures that the memory in slices
is
indeed mapped while in use. This guard must not be dropped while this vector is in use!
Trait Implementations§
Source§impl<'a> From<IoBufferRef<'a>> for IoVector<'a>
impl<'a> From<IoBufferRef<'a>> for IoVector<'a>
Source§fn from(buffer: IoBufferRef<'a>) -> Self
fn from(buffer: IoBufferRef<'a>) -> Self
Source§impl<'a> IoVectorTrait for IoVector<'a>
impl<'a> IoVectorTrait for IoVector<'a>
Source§type BufferType = IoSlice<'a>
type BufferType = IoSlice<'a>
IoSlice
or IoSliceMut
.Source§fn with_capacity(cap: usize) -> Self
fn with_capacity(cap: usize) -> Self
cap
buffers. Read moreSource§fn push_ioslice(&mut self, ioslice: Self::BufferType)
fn push_ioslice(&mut self, ioslice: Self::BufferType)
Source§fn insert(&mut self, index: usize, slice: Self::SliceType)
fn insert(&mut self, index: usize, slice: Self::SliceType)
index
in the buffer vector.Source§fn buffer_count(&self) -> usize
fn buffer_count(&self) -> usize
Source§fn append(&mut self, other: Self)
fn append(&mut self, other: Self)
Source§fn split_tail_at(self, mid: u64) -> Self
fn split_tail_at(self, mid: u64) -> Self
IoVectorTrait::split_at()
, but discards the head, only returning the tail. Read moreSource§fn copy_into_slice(&self, slice: &mut [u8])
fn copy_into_slice(&self, slice: &mut [u8])
Source§fn try_into_owned(self, alignment: usize) -> Result<IoBuffer>
fn try_into_owned(self, alignment: usize) -> Result<IoBuffer>
IoBuffer
with the same data (copied).Source§fn is_aligned(&self, mem_alignment: usize, req_alignment: usize) -> bool
fn is_aligned(&self, mem_alignment: usize, req_alignment: usize) -> bool
self
is aligned. Read moreSource§fn into_inner(self) -> Vec<Self::BufferType>
fn into_inner(self) -> Vec<Self::BufferType>
IoSlice
objects.