1use std::{mem, time};
2
3use crate::kernel;
4
5#[derive(Clone, Copy, Debug, Eq, PartialEq)]
7pub enum Progress {
8 Idle,
9 Entered,
10}
11
12#[derive(Clone, Copy, Debug, Eq, PartialEq)]
14#[repr(transparent)]
15pub struct Overflow(time::Duration);
16
17impl Overflow {
18 pub const fn new(span: time::Duration) -> Self {
19 Self(span)
20 }
21
22 pub const fn requested(self) -> time::Duration {
23 self.0
24 }
25}
26
27pub trait Enter: Sized {
29 type Error;
30 type Timeout: TryFrom<time::Duration, Error = Overflow>;
31
32 fn try_submit(self) -> Result<(), Self::Error>;
33 fn try_wait(self, timeout: Option<Self::Timeout>) -> Result<(), Self::Error>;
34 fn try_commit(self) -> Result<Progress, Self::Error>;
35}
36
37#[derive(Clone, Copy, Debug, Eq, PartialEq)]
39pub enum Poll<E, C> {
40 Timeout { requested: time::Duration },
41 Submit(E),
42 Wait(E),
43 Cancel(C),
44}
45
46impl<E, C> From<Overflow> for Poll<E, C> {
47 fn from(overflow: Overflow) -> Self {
48 Self::Timeout {
49 requested: overflow.requested(),
50 }
51 }
52}
53
54const _: () = {
55 type Failure = Poll<kernel::Errno<()>, kernel::Errno<()>>;
56 assert!(mem::size_of::<Failure>() == mem::size_of::<time::Duration>());
57 assert!(mem::align_of::<Failure>() == mem::align_of::<time::Duration>());
58 assert!(mem::size_of::<Result<(), Failure>>() == mem::size_of::<Failure>());
59};