Skip to main content

SendChain

Struct SendChain 

Source
pub struct SendChain<M: MemOps, P: BufferProvider> { /* 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, P: BufferProvider> SendChain<M, P>

Source

pub fn segment_count(&self) -> usize

Number of producer-written readable segments 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.

§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

Trait Implementations§

Source§

impl<M: MemOps, P: BufferProvider> Drop for SendChain<M, P>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

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

§

impl<M, P> RefUnwindSafe for SendChain<M, P>

§

impl<M, P> Send for SendChain<M, P>
where M: Send, P: Send,

§

impl<M, P> Sync for SendChain<M, P>
where M: Sync, P: Sync,

§

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

§

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

§

impl<M, P> UnwindSafe for SendChain<M, P>
where M: UnwindSafe, P: 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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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