Skip to main content

IoBuffers

Struct IoBuffers 

Source
pub struct IoBuffers<Buffers> { /* private fields */ }
Expand description

An owned scatter/gather package with I/O vectors prepared once at construction. The vector allocation and source owners are reused between operations; payload bytes are never copied.

use base_scheduler::{IoBuffers, IoBufSequence};
let mut buffers = IoBuffers::new([b"header".to_vec(), b"body".to_vec()]);
// After an operation returns its owner and reports a short transfer:
buffers.advance(7);
assert_eq!(buffers.buffer(0), b"ody");
let [header, body] = buffers.into_inner();
assert_eq!(header, b"header");
assert_eq!(body, b"body");

Borrowed I/O vectors cannot outlive the package, even when copied:

ⓘ
use base_scheduler::{IoBuffers, IoBufSequence};
let vector = {
    let buffers = IoBuffers::new([vec![1, 2]]);
    buffers.io_slices().unwrap()[0]
};
assert_eq!(&*vector, &[1, 2]);

Implementations§

Source§

impl<Buffers: IoBufSequence> IoBuffers<Buffers>

Source

pub fn new(buffers: Buffers) -> Self

Prepare one vector per source range, retaining the complete sequence owner. This allocates vector storage once; subsequent moves, borrows, and advancement do not allocate.

Panics on Windows if an individual byte range exceeds the IoSlice/IoSliceMut 4 GiB limit.

Source

pub fn advance(&mut self, bytes: usize)

Skip completed bytes after an operation has returned the package. Fully consumed vectors are skipped; only the first partially consumed vector is adjusted. Source owners and their original ranges are preserved.

Panics without changing the package if bytes exceeds the remaining length. Advancing by zero also skips leading empty vectors. Schedulers never advance the package automatically.

Source

pub fn into_inner(self) -> Buffers

Recover the original sequence, including fully consumed buffers and their original ranges.

Trait Implementations§

Source§

impl<Buffers: IoBufSequence> IoBufSequence for IoBuffers<Buffers>

Source§

fn buffer_count(&self) -> usize

Number of active byte ranges, including empty ranges.
Source§

fn buffer(&self, index: usize) -> &[u8] ⓘ

Borrow an active initialized byte range. Panics if index is out of bounds.
Source§

fn io_slices(&self) -> Option<&[IoSlice<'_>]>

Borrow prepared I/O vectors, when available. These must describe exactly the same ranges as buffer(). Backends can otherwise build vectors in their own reusable storage. Read more

Auto Trait Implementations§

§

impl<Buffers> Freeze for IoBuffers<Buffers>
where BufferSequenceOwner<Buffers>: Freeze,

§

impl<Buffers> RefUnwindSafe for IoBuffers<Buffers>
where BufferSequenceOwner<Buffers>: RefUnwindSafe,

§

impl<Buffers> Send for IoBuffers<Buffers>
where BufferSequenceOwner<Buffers>: Send,

§

impl<Buffers> Sync for IoBuffers<Buffers>
where BufferSequenceOwner<Buffers>: Sync,

§

impl<Buffers> Unpin for IoBuffers<Buffers>
where BufferSequenceOwner<Buffers>: Unpin,

§

impl<Buffers> UnsafeUnpin for IoBuffers<Buffers>
where BufferSequenceOwner<Buffers>: UnsafeUnpin,

§

impl<Buffers> UnwindSafe for IoBuffers<Buffers>
where BufferSequenceOwner<Buffers>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.