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