pub struct BufferChainBuilder<T> { /* private fields */ }Expand description
A builder for buffer chains using type-state to enforce readable/writable order.
Upholds invariants: at least one buffer must be present in the chain, and readable buffers must be added before writable buffers.
The builder stores up to 16 buffer elements inline to avoid allocation for common small chains. Larger chains are still supported and spill to the heap.
Implementations§
Source§impl BufferChainBuilder<Readable>
impl BufferChainBuilder<Readable>
Sourcepub fn readable(self, addr: u64, len: u32) -> Self
pub fn readable(self, addr: u64, len: u32) -> Self
Add a readable buffer (device reads from this).
Sourcepub fn readables(
self,
elements: impl IntoIterator<Item = impl Into<BufferElement>>,
) -> Self
pub fn readables( self, elements: impl IntoIterator<Item = impl Into<BufferElement>>, ) -> Self
Add multiple readable buffers from an iterator.
Sourcepub fn writable(self, addr: u64, len: u32) -> BufferChainBuilder<Writable>
pub fn writable(self, addr: u64, len: u32) -> BufferChainBuilder<Writable>
Add a writable buffer (device writes to this).
This transitions to Writable state so no more readable buffers can be added.
Sourcepub fn writables(
self,
elements: impl IntoIterator<Item = impl Into<BufferElement>>,
) -> BufferChainBuilder<Writable>
pub fn writables( self, elements: impl IntoIterator<Item = impl Into<BufferElement>>, ) -> BufferChainBuilder<Writable>
Add multiple writable buffers from an iterator.
This transitions to Writable state so no more readable buffers can be added.
Sourcepub fn build(self) -> Result<BufferChain, RingError>
pub fn build(self) -> Result<BufferChain, RingError>
Build a buffer chain with only readable buffers.
Chain must have at least one buffer otherwise an error is returned.
Source§impl BufferChainBuilder<Writable>
impl BufferChainBuilder<Writable>
Sourcepub fn writables(
self,
elements: impl IntoIterator<Item = impl Into<BufferElement>>,
) -> Self
pub fn writables( self, elements: impl IntoIterator<Item = impl Into<BufferElement>>, ) -> Self
Add multiple writable buffers from an iterator.
Sourcepub fn build(self) -> Result<BufferChain, RingError>
pub fn build(self) -> Result<BufferChain, RingError>
Build the buffer chain.
Chain must have at least one buffer otherwise an error is returned.