Remove `VmReader::collect`

This commit is contained in:
Ruihan Li 2025-07-27 17:17:16 +08:00 committed by Tate, Hongliang Tian
parent 6e597b40af
commit db79aa2453
2 changed files with 0 additions and 46 deletions

View File

@ -40,7 +40,6 @@
//! user space, making it impossible to avoid data races). However, they may produce erroneous
//! results, such as unexpected bytes being copied, but do not cause soundness problems.
use alloc::vec;
use core::marker::PhantomData;
use align_ext::AlignExt;
@ -606,25 +605,6 @@ impl VmReader<'_, Fallible> {
})?;
Ok(val)
}
/// Collects all the remaining bytes into a `Vec<u8>`.
///
/// If the memory read failed, this method will return `Err`
/// and the current reader's cursor remains pointing to
/// the original starting position.
pub fn collect(&mut self) -> Result<Vec<u8>> {
let mut buf = vec![0u8; self.remain()];
self.read_fallible(&mut buf.as_mut_slice().into())
.map_err(|(err, copied_len)| {
// SAFETY: The `copied_len` is the number of bytes read so far.
// So the `cursor` can be moved back to the original position.
unsafe {
self.cursor = self.cursor.sub(copied_len);
}
err
})?;
Ok(buf)
}
}
impl<Fallibility> VmReader<'_, Fallibility> {

View File

@ -332,32 +332,6 @@ mod io {
assert_eq!(val, read_val);
}
/// Tests the `collect` method in Fallible mode.
#[ktest]
fn collect_fallible() {
let data = [5u8, 6, 7, 8, 9];
let reader = VmReader::from(&data[..]);
let mut reader_fallible = reader.to_fallible();
let collected = reader_fallible.collect().unwrap();
assert_eq!(collected, data);
}
/// Tests partial collection in Fallible mode.
#[ktest]
fn collect_partial_fallible() {
let data = [1u8, 2, 3, 4, 5];
let reader = VmReader::from(&data[..]);
let mut reader_fallible = reader.to_fallible();
// Limits the reader to 3 bytes
let limited_reader = reader_fallible.limit(3);
let result = limited_reader.collect();
assert!(result.is_ok());
assert_eq!(result.unwrap(), vec![1, 2, 3]);
}
/// Tests the `fill_zeros` method in Fallible mode.
#[ktest]
fn fill_zeros_fallible() {