pub struct IoUring { /* private fields */ }
Expand description
An io-uring
subsystem. Can be shared between threads safely.
Will spawn a thread on creation. On drop it will stop the thread, but wait for any I/O operations
to complete first.
If this waiting is an issue to you, you should call cancel_all
to cancel all operations.
This will, however leak some memory for every active operation.
Every function that interacts with io-uring
will panic if that interaction fails. Only errors for your
operation will be returned inside the output of the future.
In theory you can check for io-uring
support using a Probe
.
§Note
Some function aren’t marked as async
, however they still return futures.
Implementations§
Source§impl IoUring
impl IoUring
Sourcepub fn open<P: AsRef<Path>>(
&self,
path: P,
flags: Flags,
) -> impl Future<Output = Result<File>>
pub fn open<P: AsRef<Path>>( &self, path: P, flags: Flags, ) -> impl Future<Output = Result<File>>
Open a file.
You can also open it using std. See [Fd
] docs.
Sourcepub fn stat<P: AsRef<Path>>(
&self,
path: P,
) -> impl Future<Output = Result<Stat>>
pub fn stat<P: AsRef<Path>>( &self, path: P, ) -> impl Future<Output = Result<Stat>>
Obtain information about a file.
Sourcepub fn read(
&self,
fd: &File,
size: u32,
) -> impl Future<Output = Result<Vec<u8>>>
pub fn read( &self, fd: &File, size: u32, ) -> impl Future<Output = Result<Vec<u8>>>
Read exactly size
bytes from a file.
This will advance the internal file cursor.
This function returns a Vec
so it can be used safely without
creating memory-leaks or use-after-free bugs.
Sourcepub async fn read_all(&self, fd: &File) -> Result<Vec<u8>>
pub async fn read_all(&self, fd: &File) -> Result<Vec<u8>>
Read the full file.
This will advance the internal file cursor.
Sourcepub fn write(
&self,
fd: &File,
buffer: Vec<u8>,
) -> impl Future<Output = Result<()>>
pub fn write( &self, fd: &File, buffer: Vec<u8>, ) -> impl Future<Output = Result<()>>
Write all the data to the file.
This will advance the internal file cursor.
Sourcepub fn cancel_all(&self) -> Result<()>
pub fn cancel_all(&self) -> Result<()>
Soft-cancels all currently running I/O operations.
This means, that if the reaper thread is stopped (by dropping this struct), this will potentially leak their memory and make their futures never complete.