Struct devices::virtio::descriptor_utils::Writer
source · pub struct Writer {
mem: GuestMemory,
regions: DescriptorChainRegions,
}
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.
Fields§
§mem: GuestMemory
§regions: DescriptorChainRegions
Implementations§
source§impl Writer
impl Writer
sourcepub fn new_from_regions(
mem: &GuestMemory,
writable_regions: SmallVec<[MemRegion; 2]>
) -> Writer ⓘ
pub fn new_from_regions( mem: &GuestMemory, writable_regions: SmallVec<[MemRegion; 2]> ) -> Writer ⓘ
Construct a new Writer wrapper over writable_regions
.
sourcepub fn write_obj<T: AsBytes>(&mut self, val: T) -> Result<()>
pub fn write_obj<T: AsBytes>(&mut self, val: T) -> Result<()>
Writes an object to the descriptor chain buffer.
sourcepub fn write_iter<T: AsBytes, I: Iterator<Item = T>>(
&mut self,
iter: I
) -> Result<()>
pub fn write_iter<T: AsBytes, I: Iterator<Item = T>>( &mut self, iter: I ) -> Result<()>
Writes all objects produced by iter
into the descriptor chain buffer. Unlike consume
,
this doesn’t require the values to be stored in an intermediate collection first. It also
allows callers to choose which elements in a collection to write, for example by using the
filter
or take
methods of the Iterator
trait.
sourcepub fn consume<T: AsBytes, C: IntoIterator<Item = T>>(
&mut self,
vals: C
) -> Result<()>
pub fn consume<T: AsBytes, C: IntoIterator<Item = T>>( &mut self, vals: C ) -> Result<()>
Writes a collection of objects into 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 write_from_volatile_slice(&mut self, slice: VolatileSlice<'_>) -> usize
pub fn write_from_volatile_slice(&mut self, slice: VolatileSlice<'_>) -> usize
Reads data into a volatile slice up to the minimum of the slice’s length or the number of bytes remaining. Returns the number of bytes read.
sourcepub fn write_from<F: FileReadWriteVolatile>(
&mut self,
src: F,
count: usize
) -> Result<usize>
pub fn write_from<F: FileReadWriteVolatile>( &mut self, src: F, count: usize ) -> Result<usize>
Writes data to the descriptor chain buffer from a readable object.
Returns the number of bytes written to the descriptor chain buffer.
The number of bytes written can be less than count
if
there isn’t enough data in the descriptor chain buffer.
sourcepub fn write_from_at<F: FileReadWriteAtVolatile>(
&mut self,
src: &F,
count: usize,
off: u64
) -> Result<usize>
pub fn write_from_at<F: FileReadWriteAtVolatile>( &mut self, src: &F, count: usize, off: u64 ) -> Result<usize>
Writes data to the descriptor chain buffer from a File at offset off
.
Returns the number of bytes written to the descriptor chain buffer.
The number of bytes written can be less than count
if
there isn’t enough data in the descriptor chain buffer.
pub fn write_all_from<F: FileReadWriteVolatile>( &mut self, src: F, count: usize ) -> Result<()>
pub fn write_all_from_at<F: FileReadWriteAtVolatile>( &mut self, src: &F, count: usize, off: u64 ) -> Result<()>
sourcepub async fn write_from_at_fut<F: AsyncDisk + ?Sized>(
&mut self,
src: &F,
count: usize,
off: u64
) -> Result<usize>
pub async fn write_from_at_fut<F: AsyncDisk + ?Sized>( &mut self, src: &F, count: usize, off: u64 ) -> Result<usize>
Writes data to the descriptor chain buffer from an AsyncDisk
at offset off
.
Returns the number of bytes written to the descriptor chain buffer.
The number of bytes written can be less than count
if
there isn’t enough data in the descriptor chain buffer.
pub async fn write_all_from_at_fut<F: AsyncDisk + ?Sized>( &mut self, src: &F, count: usize, off: u64 ) -> Result<()>
sourcepub fn bytes_written(&self) -> usize
pub fn bytes_written(&self) -> usize
Returns number of bytes already written to the descriptor chain buffer.
pub fn get_remaining_regions(&self) -> MemRegionIter<'_>
sourcepub fn get_remaining(&self) -> SmallVec<[VolatileSlice<'_>; 16]>
pub fn get_remaining(&self) -> SmallVec<[VolatileSlice<'_>; 16]>
Returns a &[VolatileSlice]
that represents all the remaining data in this Writer
.
Calling this method does not actually advance the current position of the Writer
in the
buffer and callers should call consume_bytes
to advance the Writer
. Not calling
consume_bytes
with the amount of data copied into the returned VolatileSlice
s will
result in that that data being overwritten the next time data is written into the Writer
.
sourcepub fn consume_bytes(&mut self, amt: usize)
pub fn consume_bytes(&mut self, amt: usize)
Consumes amt
bytes from the underlying descriptor chain. If amt
is larger than the
remaining data left in this Reader
, then all remaining data will be consumed.
sourcepub fn split_at(&mut self, offset: usize) -> Writer ⓘ
pub fn split_at(&mut self, offset: usize) -> Writer ⓘ
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. If offset > self.available_bytes()
, then
the returned Writer
will not be able to write any bytes.
Trait Implementations§
source§impl Write for Writer
impl Write for Writer
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
)source§impl Writer for Writer
impl Writer for Writer
§type ClosureWriter = Writer
type ClosureWriter = Writer
write_at
. For most implementations, this should be
Self
.source§fn write_at<F>(&mut self, offset: usize, f: F) -> Result<usize>
fn write_at<F>(&mut self, offset: usize, f: F) -> Result<usize>
source§fn has_sufficient_buffer(&self, size: u32) -> bool
fn has_sufficient_buffer(&self, size: u32) -> bool
source§impl ZeroCopyWriter for Writer
impl ZeroCopyWriter for Writer
source§fn write_from(&mut self, f: &mut File, count: usize, off: u64) -> Result<usize>
fn write_from(&mut self, f: &mut File, count: usize, off: u64) -> Result<usize>
count
bytes from f
at offset off
directly into self
without storing
it in any intermediate buffers. If the return value is Ok(n)
then it must be guaranteed
that 0 <= n <= count
. If n
is 0
, then it can indicate one of 3 possibilities: Read moreAuto Trait Implementations§
impl RefUnwindSafe for Writer
impl Send for Writer
impl Sync for Writer
impl Unpin for Writer
impl UnwindSafe for Writer
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.