Skip to content

Commit

Permalink
impl AsyncReadRentAt and AsyncWriteRentAt for File (#309)
Browse files Browse the repository at this point in the history
* impl ReadRentAt

* impl AsyncWriteRentAt for File

* fmt

* back to &mut
  • Loading branch information
a10y authored Oct 24, 2024
1 parent f6e50e4 commit ead462c
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion monoio/src/fs/file/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::{io, path::Path};
use std::{future::Future, io, path::Path};

use crate::{
buf::{IoBuf, IoBufMut, IoVecBuf, IoVecBufMut},
driver::{op::Op, shared_fd::SharedFd},
fs::OpenOptions,
io::{AsyncReadRent, AsyncWriteRent},
BufResult,
};

#[cfg(unix)]
Expand All @@ -16,6 +17,8 @@ mod windows;
#[cfg(windows)]
use windows as file_impl;

use crate::io::{AsyncReadRentAt, AsyncWriteRentAt};

/// A reference to an open file on the filesystem.
///
/// An instance of a `File` can be read and/or written depending on what options
Expand Down Expand Up @@ -635,6 +638,16 @@ impl AsyncWriteRent for File {
}
}

impl AsyncWriteRentAt for File {
fn write_at<T: IoBuf>(
&mut self,
buf: T,
pos: usize,
) -> impl Future<Output = BufResult<usize, T>> {
File::write_at(self, buf, pos as u64)
}
}

impl AsyncReadRent for File {
/// Reads bytes from the file at the current file pointer into the specified buffer, returning
/// the number of bytes read.
Expand Down Expand Up @@ -753,3 +766,13 @@ impl AsyncReadRent for File {
self.read_vectored(buf).await
}
}

impl AsyncReadRentAt for File {
fn read_at<T: IoBufMut>(
&mut self,
buf: T,
pos: usize,
) -> impl Future<Output = BufResult<usize, T>> {
File::read_at(self, buf, pos as u64)
}
}

0 comments on commit ead462c

Please sign in to comment.