pub struct Writer<'a, B = ()> { /* private fields */ }
Expand description
Provides high-level interface over the sequence of memory regions defined by writable descriptors in the descriptor chain.
Note that virtio spec requires driver to place any device-writable descriptors after any device-readable descriptors (2.6.4.2 in Virtio Spec v1.1). Writer will start iterating the descriptors from the first writable one and will assume that all following descriptors are writable.
Implementations§
Source§impl<'a, B: BitmapSlice> Writer<'a, B>
impl<'a, B: BitmapSlice> Writer<'a, B>
Sourcepub fn new<M, T>(
mem: &'a M,
desc_chain: DescriptorChain<T>,
) -> Result<Writer<'a, B>, Error>where
M: GuestMemory,
<<M as GuestMemory>::R as GuestMemoryRegion>::B: WithBitmapSlice<'a, S = B>,
T: Deref,
T::Target: GuestMemory + Sized,
pub fn new<M, T>(
mem: &'a M,
desc_chain: DescriptorChain<T>,
) -> Result<Writer<'a, B>, Error>where
M: GuestMemory,
<<M as GuestMemory>::R as GuestMemoryRegion>::B: WithBitmapSlice<'a, S = B>,
T: Deref,
T::Target: GuestMemory + Sized,
Construct a new Writer wrapper over desc_chain
.
Sourcepub fn write_obj<T: ByteValued>(&mut self, val: T) -> Result<()>
pub fn write_obj<T: ByteValued>(&mut self, val: T) -> Result<()>
Writes an object to the descriptor chain buffer.
Sourcepub fn available_bytes(&self) -> usize
pub fn available_bytes(&self) -> usize
Returns number of bytes available for writing. May return an error if the combined lengths of all the buffers in the DescriptorChain would cause an overflow.
Sourcepub fn bytes_written(&self) -> usize
pub fn bytes_written(&self) -> usize
Returns number of bytes already written to the descriptor chain buffer.
Sourcepub fn split_at(&mut self, offset: usize) -> Result<Writer<'a, B>, Error>
pub fn split_at(&mut self, offset: usize) -> Result<Writer<'a, B>, Error>
Splits this Writer
into two at the given offset in the DescriptorChain
buffer.
After the split, self
will be able to write up to offset
bytes while the returned
Writer
can write up to available_bytes() - offset
bytes. Returns an error if
offset > self.available_bytes()
.
Trait Implementations§
Source§impl<B: BitmapSlice> Write for Writer<'_, B>
impl<B: BitmapSlice> Write for Writer<'_, B>
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)