pub trait VmIoFill {
// Required method
fn fill_zeros(
&self,
offset: usize,
len: usize,
) -> Result<(), (Error, usize)>;
}
Expand description
A trait that enables filling bytes (e.g., filling zeros) to a VM object.
Required Methods§
Sourcefn fill_zeros(&self, offset: usize, len: usize) -> Result<(), (Error, usize)>
fn fill_zeros(&self, offset: usize, len: usize) -> Result<(), (Error, usize)>
Writes len
zeros at a specified offset.
Unlike the methods in VmIo
, this method allows for short writes because len
can be
effectively unbounded. However, if not all bytes can be written successfully, an Err(_)
will be returned with the error and the number of zeros that have been written thus far.
§A slow, general implementation
Suppose that VmIo
has already been implemented for the type,
this method can be implemented in the following general way.
fn fill_zeros(&self, offset: usize, len: usize) -> core::result::Result<(), (Error, usize)> {
for i in 0..len {
match self.write_slice(offset + i, &[0u8]) {
Ok(()) => continue,
Err(err) => return Err((err, i)),
}
}
Ok(())
}
But we choose not to provide a general, default implementation
because doing so would make it too easy for a concrete type of VmIoFill
to settle with a slower implementation for such a performance-sensitive operation.