Make VmReader's several methods accept &mut self

This commit is contained in:
jiangjianfeng
2025-03-24 03:35:28 +00:00
committed by Qingsong Chen
parent 9872adaa71
commit 0e1c660225
9 changed files with 58 additions and 56 deletions

View File

@ -305,23 +305,15 @@ impl<Dma: AsRef<DmaStream>> DmaStreamSlice<Dma> {
/// Returns a reader to read data from it.
pub fn reader(&self) -> Result<VmReader<Infallible>, Error> {
let stream_reader = self
.stream
.as_ref()
.reader()?
.skip(self.offset)
.limit(self.len);
let mut stream_reader = self.stream.as_ref().reader()?;
stream_reader.skip(self.offset).limit(self.len);
Ok(stream_reader)
}
/// Returns a writer to write data into it.
pub fn writer(&self) -> Result<VmWriter<Infallible>, Error> {
let stream_writer = self
.stream
.as_ref()
.writer()?
.skip(self.offset)
.limit(self.len);
let mut stream_writer = self.stream.as_ref().writer()?;
stream_writer.skip(self.offset).limit(self.len);
Ok(stream_writer)
}
}

View File

@ -629,7 +629,7 @@ impl<Fallibility> VmReader<'_, Fallibility> {
/// Limits the length of remaining data.
///
/// This method ensures the post condition of `self.remain() <= max_remain`.
pub const fn limit(mut self, max_remain: usize) -> Self {
pub const fn limit(&mut self, max_remain: usize) -> &mut Self {
if max_remain < self.remain() {
// SAFETY: the new end is less than the old end.
unsafe { self.end = self.cursor.add(max_remain) };
@ -643,7 +643,7 @@ impl<Fallibility> VmReader<'_, Fallibility> {
/// # Panics
///
/// If `nbytes` is greater than `self.remain()`, then the method panics.
pub fn skip(mut self, nbytes: usize) -> Self {
pub fn skip(&mut self, nbytes: usize) -> &mut Self {
assert!(nbytes <= self.remain());
// SAFETY: the new cursor is less than or equal to the end.
@ -893,7 +893,7 @@ impl<Fallibility> VmWriter<'_, Fallibility> {
/// Limits the length of available space.
///
/// This method ensures the post condition of `self.avail() <= max_avail`.
pub const fn limit(mut self, max_avail: usize) -> Self {
pub const fn limit(&mut self, max_avail: usize) -> &mut Self {
if max_avail < self.avail() {
// SAFETY: the new end is less than the old end.
unsafe { self.end = self.cursor.add(max_avail) };
@ -907,7 +907,7 @@ impl<Fallibility> VmWriter<'_, Fallibility> {
/// # Panics
///
/// If `nbytes` is greater than `self.avail()`, then the method panics.
pub fn skip(mut self, nbytes: usize) -> Self {
pub fn skip(&mut self, nbytes: usize) -> &mut Self {
assert!(nbytes <= self.avail());
// SAFETY: the new cursor is less than or equal to the end.