Remove `VmWriter::fill`

This commit is contained in:
Ruihan Li 2025-07-27 23:56:24 +08:00 committed by Tate, Hongliang Tian
parent db79aa2453
commit d99c18d0be
2 changed files with 0 additions and 45 deletions

View File

@ -754,36 +754,6 @@ impl<'a> VmWriter<'a, Infallible> {
Ok(())
}
/// Fills the available space by repeating `value`.
///
/// Returns the number of values written.
///
/// # Panics
///
/// The size of the available space must be a multiple of the size of `value`.
/// Otherwise, the method would panic.
pub fn fill<T: Pod>(&mut self, value: T) -> usize {
let cursor = self.cursor.cast::<T>();
assert!(cursor.is_aligned());
let avail = self.avail();
assert!(avail % core::mem::size_of::<T>() == 0);
let written_num = avail / core::mem::size_of::<T>();
for i in 0..written_num {
let cursor_i = cursor.wrapping_add(i);
// SAFETY: `written_num` is calculated by the avail size and the size of the type `T`,
// so the `write` operation will only manipulate the memory managed by this writer.
// We've checked that the cursor is properly aligned with respect to the type `T`. All
// other safety requirements are the same as for `Self::write`.
unsafe { cursor_i.write_volatile(value) };
}
// The available space has been filled so this cursor can be moved to the end.
self.cursor = self.end;
written_num
}
/// Converts to a fallible writer.
pub fn to_fallible(self) -> VmWriter<'a, Fallible> {
// It is safe to construct a fallible reader since an infallible reader covers the

View File

@ -118,21 +118,6 @@ mod io {
writer_infallible.write_val(&val).unwrap();
}
/// Tests the `fill` method in Infallible mode.
#[ktest]
fn fill_infallible() {
let mut buffer = vec![0u8; 8];
let mut writer_infallible = VmWriter::from(&mut buffer[..]);
// Fill with 0xFF
let filled = writer_infallible.fill(0xFFu8);
assert_eq!(filled, 8);
// Ensure the cursor is at the end
assert_eq!(writer_infallible.avail(), 0);
assert_eq!(buffer, vec![0xFF; 8]);
}
/// Tests the `skip` method for reading in Infallible mode.
#[ktest]
fn skip_read_infallible() {