io_uring_opcode/
traits.rs

1//! UringOpCode represents the API between the io-uring-bearer and the
2//! individual io_uring OpCode handlers which are sepated into different
3//! crates.
4
5#[cfg(feature = "epoll")]
6mod epoll_ctl;
7#[cfg(feature = "epoll")]
8pub use epoll_ctl::OpExtEpollCtl;
9
10use core::pin::Pin;
11use io_uring_owner::Owner;
12
13use crate::OpError;
14
15/// Pending Completion type implemented by the OpCode handlers.
16pub trait OpCompletion {
17    /// It is recommended that you use a harmonized error type but is not mandatory.
18    type Error;
19    /// Provide the squeue entry
20    fn entry(&self) -> io_uring::squeue::Entry;
21    /// Get the current Owner
22    fn owner(&self) -> Owner;
23    /// Force set the owner to Kernel
24    fn force_owner_kernel(&mut self) -> bool;
25}
26
27/// The contracting type between io-uring-bearer and all the opcodes it can carry.
28/// Implement this type in the individual opcodes that can be used in the bearer.
29pub trait OpCode<C: OpCompletion> {
30    /// It is recommended that you use a harmonized error type but is not mandatory.
31    // Turn the abstract OpCoe into Submission that will be pending completion.
32    // io-uring-bearer will call this in order to convert the higher level type into actual submission.
33    fn submission(self) -> Result<C, OpError>;
34    /// io-uring-bearer will call this upno completion
35    fn completion(&mut self, _: Pin<&mut C>) -> Result<(), OpError>;
36}