mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-29 15:43:21 +00:00
Make VmReader's several methods accept &mut self
This commit is contained in:
committed by
Qingsong Chen
parent
9872adaa71
commit
0e1c660225
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
|
Reference in New Issue
Block a user