1#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
2#[repr(transparent)]
3pub struct PollEvents(u16);
4
5impl PollEvents {
6 pub const NONE: Self = Self(0);
8 pub const DATA_AVAILABLE: Self = Self(1 << 0);
10 pub const CAN_WRITE: Self = Self(1 << 1);
12 pub const DISCONNECTED: Self = Self(1 << 2);
15 pub const ALL: Self = Self(u16::MAX);
17
18 pub const fn contains(&self, other: Self) -> bool {
19 self.0 & other.0 == other.0
20 }
21
22 pub const fn intersects(&self, other: Self) -> bool {
23 self.0 & other.0 != 0
24 }
25
26 pub const fn is_empty(&self) -> bool {
27 self.0 == 0
28 }
29
30 pub const fn union(&self, other: Self) -> Self {
31 Self(self.0 | other.0)
32 }
33
34 pub const fn intersection(&self, other: Self) -> Self {
35 Self(self.0 & other.0)
36 }
37
38 pub const fn difference(&self, other: Self) -> Self {
39 Self(self.0 & !other.0)
40 }
41}
42
43#[derive(Debug, Clone, Copy, PartialEq, Eq)]
45#[repr(C)]
46pub struct PollEntry {
47 resource: u32,
48 events: PollEvents,
49 returned_events: PollEvents,
50}
51
52impl PollEntry {
53 pub const fn new(resource: u32, events: PollEvents) -> Self {
54 Self {
55 resource,
56 events,
57 returned_events: PollEvents::NONE,
58 }
59 }
60
61 pub const fn resource(&self) -> u32 {
63 self.resource
64 }
65
66 pub const fn events(&self) -> PollEvents {
68 self.events
69 }
70
71 pub const fn returned_events(&self) -> PollEvents {
73 self.returned_events
74 }
75
76 pub const fn returned_events_mut(&mut self) -> &mut PollEvents {
78 &mut self.returned_events
79 }
80}