1 use event_imp::{Ready, ready_as_usize, ready_from_usize};
2 pub use zircon_sys::{
3     zx_signals_t,
4     ZX_OBJECT_READABLE,
5     ZX_OBJECT_WRITABLE,
6 };
7 use std::ops;
8 
9 // The following impls are valid because Fuchsia and mio both represent
10 // "readable" as `1 << 0` and "writable" as `1 << 2`.
11 // We define this assertion here and call it from `Selector::new`,
12 // since `Selector:;new` is guaranteed to be called during a standard mio runtime,
13 // unlike the functions in this file.
14 #[inline]
assert_fuchsia_ready_repr()15 pub fn assert_fuchsia_ready_repr() {
16     debug_assert!(
17         ZX_OBJECT_READABLE.bits() as usize == ready_as_usize(Ready::readable()),
18         "Zircon ZX_OBJECT_READABLE should have the same repr as Ready::readable()"
19     );
20     debug_assert!(
21         ZX_OBJECT_WRITABLE.bits() as usize == ready_as_usize(Ready::writable()),
22         "Zircon ZX_OBJECT_WRITABLE should have the same repr as Ready::writable()"
23     );
24 }
25 
26 /// Fuchsia specific extensions to `Ready`
27 ///
28 /// Provides additional readiness event kinds that are available on Fuchsia.
29 ///
30 /// Conversion traits are implemented between `Ready` and `FuchsiaReady`.
31 ///
32 /// For high level documentation on polling and readiness, see [`Poll`].
33 ///
34 /// [`Poll`]: struct.Poll.html
35 #[derive(Debug, Copy, PartialEq, Eq, Clone, PartialOrd, Ord)]
36 pub struct FuchsiaReady(Ready);
37 
38 impl FuchsiaReady {
39     /// Returns the `FuchsiaReady` as raw zircon signals.
40     /// This function is just a more explicit, non-generic version of
41     /// `FuchsiaReady::into`.
42     #[inline]
into_zx_signals(self) -> zx_signals_t43     pub fn into_zx_signals(self) -> zx_signals_t {
44         zx_signals_t::from_bits_truncate(ready_as_usize(self.0) as u32)
45     }
46 }
47 
48 impl Into<zx_signals_t> for FuchsiaReady {
49     #[inline]
into(self) -> zx_signals_t50     fn into(self) -> zx_signals_t {
51         self.into_zx_signals()
52     }
53 }
54 
55 impl From<zx_signals_t> for FuchsiaReady {
56     #[inline]
from(src: zx_signals_t) -> Self57     fn from(src: zx_signals_t) -> Self {
58         FuchsiaReady(src.into())
59     }
60 }
61 
62 impl From<zx_signals_t> for Ready {
63     #[inline]
from(src: zx_signals_t) -> Self64     fn from(src: zx_signals_t) -> Self {
65         ready_from_usize(src.bits() as usize)
66     }
67 }
68 
69 impl From<Ready> for FuchsiaReady {
70     #[inline]
from(src: Ready) -> FuchsiaReady71     fn from(src: Ready) -> FuchsiaReady {
72         FuchsiaReady(src)
73     }
74 }
75 
76 impl From<FuchsiaReady> for Ready {
77     #[inline]
from(src: FuchsiaReady) -> Ready78     fn from(src: FuchsiaReady) -> Ready {
79         src.0
80     }
81 }
82 
83 impl ops::Deref for FuchsiaReady {
84     type Target = Ready;
85 
86     #[inline]
deref(&self) -> &Ready87     fn deref(&self) -> &Ready {
88         &self.0
89     }
90 }
91 
92 impl ops::DerefMut for FuchsiaReady {
93     #[inline]
deref_mut(&mut self) -> &mut Ready94     fn deref_mut(&mut self) -> &mut Ready {
95         &mut self.0
96     }
97 }
98 
99 impl ops::BitOr for FuchsiaReady {
100     type Output = FuchsiaReady;
101 
102     #[inline]
bitor(self, other: FuchsiaReady) -> FuchsiaReady103     fn bitor(self, other: FuchsiaReady) -> FuchsiaReady {
104         (self.0 | other.0).into()
105     }
106 }
107 
108 impl ops::BitXor for FuchsiaReady {
109     type Output = FuchsiaReady;
110 
111     #[inline]
bitxor(self, other: FuchsiaReady) -> FuchsiaReady112     fn bitxor(self, other: FuchsiaReady) -> FuchsiaReady {
113         (self.0 ^ other.0).into()
114     }
115 }
116 
117 impl ops::BitAnd for FuchsiaReady {
118     type Output = FuchsiaReady;
119 
120     #[inline]
bitand(self, other: FuchsiaReady) -> FuchsiaReady121     fn bitand(self, other: FuchsiaReady) -> FuchsiaReady {
122         (self.0 & other.0).into()
123     }
124 }
125 
126 impl ops::Sub for FuchsiaReady {
127     type Output = FuchsiaReady;
128 
129     #[inline]
sub(self, other: FuchsiaReady) -> FuchsiaReady130     fn sub(self, other: FuchsiaReady) -> FuchsiaReady {
131         (self.0 & !other.0).into()
132     }
133 }
134 
135 #[deprecated(since = "0.6.10", note = "removed")]
136 #[cfg(feature = "with-deprecated")]
137 #[doc(hidden)]
138 impl ops::Not for FuchsiaReady {
139     type Output = FuchsiaReady;
140 
141     #[inline]
not(self) -> FuchsiaReady142     fn not(self) -> FuchsiaReady {
143         (!self.0).into()
144     }
145 }
146 
147 impl ops::BitOr<zx_signals_t> for FuchsiaReady {
148     type Output = FuchsiaReady;
149 
150     #[inline]
bitor(self, other: zx_signals_t) -> FuchsiaReady151     fn bitor(self, other: zx_signals_t) -> FuchsiaReady {
152         self | FuchsiaReady::from(other)
153     }
154 }
155 
156 impl ops::BitXor<zx_signals_t> for FuchsiaReady {
157     type Output = FuchsiaReady;
158 
159     #[inline]
bitxor(self, other: zx_signals_t) -> FuchsiaReady160     fn bitxor(self, other: zx_signals_t) -> FuchsiaReady {
161         self ^ FuchsiaReady::from(other)
162     }
163 }
164 
165 impl ops::BitAnd<zx_signals_t> for FuchsiaReady {
166     type Output = FuchsiaReady;
167 
168     #[inline]
bitand(self, other: zx_signals_t) -> FuchsiaReady169     fn bitand(self, other: zx_signals_t) -> FuchsiaReady {
170         self & FuchsiaReady::from(other)
171     }
172 }
173 
174 impl ops::Sub<zx_signals_t> for FuchsiaReady {
175     type Output = FuchsiaReady;
176 
177     #[inline]
sub(self, other: zx_signals_t) -> FuchsiaReady178     fn sub(self, other: zx_signals_t) -> FuchsiaReady {
179         self - FuchsiaReady::from(other)
180     }
181 }
182