Struct IoUring

Source
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

Source

pub fn new() -> Result<Self>

Create a new io-uring context.

Will spawn a reaper thread.

Source

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.

Source

pub fn stat<P: AsRef<Path>>( &self, path: P, ) -> impl Future<Output = Result<Stat>>

Obtain information about a file.

Source

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.

Source

pub async fn read_all(&self, fd: &File) -> Result<Vec<u8>>

Read the full file.

This will advance the internal file cursor.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Drop for IoUring

Source§

fn drop(&mut self)

On drop: Shut down the reaper thread, blocking for pending operations to complete and free their memory.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.