Struct devices::virtio::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

source

pub fn new_from_regions( mem: &GuestMemory, writable_regions: SmallVec<[MemRegion; 2]> ) -> Writer

Construct a new Writer wrapper over writable_regions.

source

pub fn write_obj<T: AsBytes>(&mut self, val: T) -> Result<()>

Writes an object to the descriptor chain buffer.

source

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.

source

pub fn consume<T: AsBytes, C: IntoIterator<Item = T>>( &mut self, vals: C ) -> Result<()>

Writes a collection of objects into the descriptor chain buffer.

source

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.

source

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.

source

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.

source

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.

source

pub fn write_all_from<F: FileReadWriteVolatile>( &mut self, src: F, count: usize ) -> Result<()>

source

pub fn write_all_from_at<F: FileReadWriteAtVolatile>( &mut self, src: &F, count: usize, off: u64 ) -> Result<()>

source

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.

source

pub async fn write_all_from_at_fut<F: AsyncDisk + ?Sized>( &mut self, src: &F, count: usize, off: u64 ) -> Result<()>

source

pub fn bytes_written(&self) -> usize

Returns number of bytes already written to the descriptor chain buffer.

source

pub fn get_remaining_regions(&self) -> MemRegionIter<'_>

source

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 VolatileSlices will result in that that data being overwritten the next time data is written into the Writer.

source

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.

source

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

source§

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

Write a buffer into this writer, returning how many bytes were written. Read more
source§

fn flush(&mut self) -> Result<()>

Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
1.36.0 · source§

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize, Error>

Like write, except that it writes from a slice of buffers. Read more
source§

fn is_write_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
1.0.0 · source§

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

Attempts to write an entire buffer into this writer. Read more
source§

fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>

🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
1.0.0 · source§

fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<(), Error>

Writes a formatted string into this writer, returning any error encountered. Read more
1.0.0 · source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Write. Read more
source§

impl Writer for Writer

§

type ClosureWriter = Writer

The type passed in to the closure in write_at. For most implementations, this should be Self.
source§

fn write_at<F>(&mut self, offset: usize, f: F) -> Result<usize>
where F: Fn(&mut Self) -> Result<usize>,

Allows a closure to generate and write data at the current writer’s offset. The current writer is passed as a mutable reference to the closure. As an example, this provides an adapter for the read implementation of a filesystem to write directly to the final buffer without generating the FUSE header first. Read more
source§

fn has_sufficient_buffer(&self, size: u32) -> bool

Checks if the writer can still accept certain amount of data.
source§

impl ZeroCopyWriter for Writer

source§

fn write_from(&mut self, f: &mut File, count: usize, off: u64) -> Result<usize>

Copies at most 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 more
source§

fn write_all_from( &mut self, f: &mut File, count: usize, off: u64 ) -> Result<(), Error>

Copies exactly count bytes of data from f at offset off into self. off + count must be less than u64::MAX. Read more
source§

fn copy_to_end(&mut self, f: &mut File, off: u64) -> Result<usize, Error>

Copies all remaining bytes from f at offset off into self. Equivalent to repeatedly calling write_from until it returns either Ok(0) or a non-ErrorKind::Interrupted error. Read more

Auto Trait Implementations§

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
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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>,

§

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>,

§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<W> WriteBytesExt for W
where W: Write + ?Sized,

§

fn write_u8(&mut self, n: u8) -> Result<(), Error>

Writes an unsigned 8 bit integer to the underlying writer. Read more
§

fn write_i8(&mut self, n: i8) -> Result<(), Error>

Writes a signed 8 bit integer to the underlying writer. Read more
§

fn write_u16<T>(&mut self, n: u16) -> Result<(), Error>
where T: ByteOrder,

Writes an unsigned 16 bit integer to the underlying writer. Read more
§

fn write_i16<T>(&mut self, n: i16) -> Result<(), Error>
where T: ByteOrder,

Writes a signed 16 bit integer to the underlying writer. Read more
§

fn write_u24<T>(&mut self, n: u32) -> Result<(), Error>
where T: ByteOrder,

Writes an unsigned 24 bit integer to the underlying writer. Read more
§

fn write_i24<T>(&mut self, n: i32) -> Result<(), Error>
where T: ByteOrder,

Writes a signed 24 bit integer to the underlying writer. Read more
§

fn write_u32<T>(&mut self, n: u32) -> Result<(), Error>
where T: ByteOrder,

Writes an unsigned 32 bit integer to the underlying writer. Read more
§

fn write_i32<T>(&mut self, n: i32) -> Result<(), Error>
where T: ByteOrder,

Writes a signed 32 bit integer to the underlying writer. Read more
§

fn write_u48<T>(&mut self, n: u64) -> Result<(), Error>
where T: ByteOrder,

Writes an unsigned 48 bit integer to the underlying writer. Read more
§

fn write_i48<T>(&mut self, n: i64) -> Result<(), Error>
where T: ByteOrder,

Writes a signed 48 bit integer to the underlying writer. Read more
§

fn write_u64<T>(&mut self, n: u64) -> Result<(), Error>
where T: ByteOrder,

Writes an unsigned 64 bit integer to the underlying writer. Read more
§

fn write_i64<T>(&mut self, n: i64) -> Result<(), Error>
where T: ByteOrder,

Writes a signed 64 bit integer to the underlying writer. Read more
§

fn write_u128<T>(&mut self, n: u128) -> Result<(), Error>
where T: ByteOrder,

Writes an unsigned 128 bit integer to the underlying writer.
§

fn write_i128<T>(&mut self, n: i128) -> Result<(), Error>
where T: ByteOrder,

Writes a signed 128 bit integer to the underlying writer.
§

fn write_uint<T>(&mut self, n: u64, nbytes: usize) -> Result<(), Error>
where T: ByteOrder,

Writes an unsigned n-bytes integer to the underlying writer. Read more
§

fn write_int<T>(&mut self, n: i64, nbytes: usize) -> Result<(), Error>
where T: ByteOrder,

Writes a signed n-bytes integer to the underlying writer. Read more
§

fn write_uint128<T>(&mut self, n: u128, nbytes: usize) -> Result<(), Error>
where T: ByteOrder,

Writes an unsigned n-bytes integer to the underlying writer. Read more
§

fn write_int128<T>(&mut self, n: i128, nbytes: usize) -> Result<(), Error>
where T: ByteOrder,

Writes a signed n-bytes integer to the underlying writer. Read more
§

fn write_f32<T>(&mut self, n: f32) -> Result<(), Error>
where T: ByteOrder,

Writes a IEEE754 single-precision (4 bytes) floating point number to the underlying writer. Read more
§

fn write_f64<T>(&mut self, n: f64) -> Result<(), Error>
where T: ByteOrder,

Writes a IEEE754 double-precision (8 bytes) floating point number to the underlying writer. Read more
§

impl<W> WriteToDescriptorChain for W
where W: Write,

§

fn write_obj<T>(&mut self, obj: T) -> Result<(), Error>
where T: VmediaType,

Write an arbitrary object to the guest.
§

fn write_response<T>(&mut self, response: T) -> Result<(), Error>
where T: VmediaType,

Write a command response to the guest.
§

fn write_err_response(&mut self, code: i32) -> Result<(), Error>

Send code as the error code of an error response.