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