Skip to main content

SendChain

Struct SendChain 

Source
pub struct SendChain<M> { /* private fields */ }
Expand description

A configured send chain ready for writing and submission.

Created by ChainBuilder::build. Write readable payload bytes directly on the chain, then submit via VirtqProducer::submit.

§Examples

ⓘ
let mut sc = producer.chain().readable(64).writable(128).build()?;
sc.write_all(b"header")?.write_all(b" body")?;
let tok = producer.submit(sc)?;

let mut sc = producer.chain().readable(128).build()?;
sc.with_seg(0, |buf| serialize_into(buf))?;
let tok = producer.submit(sc)?;

Copy writes (write/write_all) and direct writes (write_seg/with_seg) must not be mixed on the same chain; doing so panics in debug builds.

If dropped without submitting, allocated buffers are returned to the pool.

Implementations§

Source§

impl<M: MemOps> SendChain<M>

Source

pub fn desc_count(&self) -> usize

Total number of descriptors in this chain.

Source

pub fn rd_desc_count(&self) -> usize

Number of readable descriptors in this chain.

Source

pub fn wr_desc_count(&self) -> usize

Number of writable descriptors in this chain.

Source

pub fn capacity(&self) -> usize

Total producer-written readable capacity in bytes.

Source

pub fn written(&self) -> usize

Number of producer-written readable bytes written so far.

Source

pub fn remaining(&self) -> usize

Remaining producer-written readable capacity.

Source

pub fn write(&mut self, buf: &[u8]) -> Result<usize, VirtqError>

Write bytes into payload segments, returning how many bytes were written.

Appends at the current aggregate write position and scatters across readable segments in chain order. Uses MemOps::write (volatile on host side). If buf is larger than the remaining capacity, writes as many bytes as will fit. If a later memory write fails, the cursor and written length retain any earlier chunks written by the same call.

§Errors
Source

pub fn write_all(&mut self, buf: &[u8]) -> Result<&mut Self, VirtqError>

Write the entire buffer into payload segments.

Appends at the current aggregate write position and scatters across readable segments in chain order. Uses MemOps::write (volatile on host side).

§Errors
Source

pub fn write_seg( &mut self, index: usize, buf: &[u8], ) -> Result<&mut Self, VirtqError>

Write bytes into one readable segment by index.

Writes from the start of the selected segment and records buf.len() as that segment’s descriptor length.

§Errors
Source

pub fn with_seg<E>( &mut self, index: usize, f: impl FnOnce(&mut [u8]) -> Result<usize, E>, ) -> Result<&mut Self, E>
where E: From<VirtqError>,

Serialize directly into one readable segment by index.

The closure returns the number of valid bytes it wrote. The written length for that segment is recorded on success.

§Errors

Auto Trait Implementations§

§

impl<M> !RefUnwindSafe for SendChain<M>

§

impl<M> !Send for SendChain<M>

§

impl<M> !Sync for SendChain<M>

§

impl<M> !UnwindSafe for SendChain<M>

§

impl<M> Freeze for SendChain<M>
where OwnedChain<M>: Freeze,

§

impl<M> Unpin for SendChain<M>
where OwnedChain<M>: Unpin,

§

impl<M> UnsafeUnpin for SendChain<M>
where OwnedChain<M>: UnsafeUnpin,

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more