diff --git a/ostd/src/mm/io.rs b/ostd/src/mm/io.rs index 3872ae081..eee1a512c 100644 --- a/ostd/src/mm/io.rs +++ b/ostd/src/mm/io.rs @@ -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`. - /// - /// 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> { - 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 VmReader<'_, Fallibility> { diff --git a/ostd/src/mm/test.rs b/ostd/src/mm/test.rs index ac5e77e37..2ff2905b2 100644 --- a/ostd/src/mm/test.rs +++ b/ostd/src/mm/test.rs @@ -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() {