dope_core/driver/
completion.rs1use std::io;
2use std::time::Duration;
3
4use crate::backend::Backend;
5use crate::backend::ops::completion::CompletionBackend;
6use crate::io::Event;
7
8use super::DriverContext;
9
10pub trait Completion<'d> {
11 fn drain(&mut self, buf: &mut [Option<Event<'d>>]) -> usize;
12 fn wait(&mut self, timeout: Option<Duration>) -> io::Result<()>;
13}
14
15impl<'d> Completion<'d> for DriverContext<'_, 'd> {
16 fn drain(&mut self, buf: &mut [Option<Event<'d>>]) -> usize {
17 self.flush_returned_buffers();
18 let reference = self.driver_ref();
19 <Backend as CompletionBackend>::drain(self.backend(), reference, buf)
20 }
21
22 fn wait(&mut self, timeout: Option<Duration>) -> io::Result<()> {
23 self.flush_returned_buffers();
24 <Backend as CompletionBackend>::wait(self.backend(), timeout)
25 }
26}