pub struct Segments { /* private fields */ }Expand description
Ordered byte segments that make up one virtqueue payload.
This is the high-level counterpart to the descriptor-oriented
BufferChain.
Implementations§
Source§impl Segments
impl Segments
Sourcepub fn new(segments: impl IntoIterator<Item = Bytes>) -> Self
pub fn new(segments: impl IntoIterator<Item = Bytes>) -> Self
Build a segmented payload from ordered byte segments.
Sourcepub fn segment_count(&self) -> usize
pub fn segment_count(&self) -> usize
Number of byte segments.
Sourcepub fn append(&mut self, other: Self)
pub fn append(&mut self, other: Self)
Append another payload without copying its bytes.
Compacts consumed slots before extending the segment list.
Sourcepub fn split_to(&mut self, len: usize) -> Option<Self>
pub fn split_to(&mut self, len: usize) -> Option<Self>
Split off an owned byte prefix without copying payload data.
Scans only the prefix, then transfers its segments without shifting the
remainder. A boundary segment shares its Bytes owner.
Returns None and leaves self unchanged when len exceeds the
remaining payload length.
Sourcepub fn as_buf(&self) -> SegmentsBuf<'_>
pub fn as_buf(&self) -> SegmentsBuf<'_>
Borrow this payload as a Buf cursor.
Sourcepub fn to_bytes(&self) -> Bytes
pub fn to_bytes(&self) -> Bytes
Return this payload as contiguous bytes.
This is O(1) for zero or one segment, and allocates/copies for multiple segments.
Sourcepub fn into_bytes(self) -> Bytes
pub fn into_bytes(self) -> Bytes
Consume this payload and return contiguous bytes.
Reuses a single segment’s storage, and allocates/copies for multiple segments.
Sourcepub fn into_chunks(self) -> Vec<Bytes>
pub fn into_chunks(self) -> Vec<Bytes>
Consume this payload without flattening its segments.