Skip to main content

dope_core/driver/result/poll/
dispatch.rs

1use std::task;
2
3use poll::fault;
4
5use crate::{driver::result::poll, io};
6
7/// Exact failure from native dispatch or completion decoding.
8#[derive(Debug, Clone, Copy, Eq, PartialEq)]
9pub enum Failure {
10    Native(poll::Error),
11    Completion(fault::Dispatch),
12}
13
14/// Direct source dispatch retaining at most one materialized event while all
15/// remaining completions stay in the backend's compact queue.
16#[must_use = "a retained event or pending source must be driven before blocking"]
17pub enum Dispatch<'d> {
18    Ready {
19        drain: poll::Drain,
20        retained: Option<io::Event<'d>>,
21    },
22    Fault(Failure),
23}
24
25impl<'d> From<(task::Poll<()>, Option<io::Event<'d>>)> for Dispatch<'d> {
26    fn from((state, retained): (task::Poll<()>, Option<io::Event<'d>>)) -> Self {
27        Self::Ready {
28            drain: state.into(),
29            retained,
30        }
31    }
32}
33
34impl From<(task::Poll<()>, fault::Fault)> for Dispatch<'_> {
35    fn from((state, failure): (task::Poll<()>, fault::Fault)) -> Self {
36        Self::Fault(Failure::Completion(fault::Dispatch::new(
37            state.into(),
38            failure,
39        )))
40    }
41}