summaryrefslogtreecommitdiffstats
path: root/third_party/rust/mio-0.6.23/src/sys/fuchsia/ready.rs
blob: 97854f8c07df1144f70f581665bb371daad37520 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
use event_imp::{Ready, ready_as_usize, ready_from_usize};
pub use zircon_sys::{
    zx_signals_t,
    ZX_OBJECT_READABLE,
    ZX_OBJECT_WRITABLE,
};
use std::ops;

// The following impls are valid because Fuchsia and mio both represent
// "readable" as `1 << 0` and "writable" as `1 << 2`.
// We define this assertion here and call it from `Selector::new`,
// since `Selector:;new` is guaranteed to be called during a standard mio runtime,
// unlike the functions in this file.
#[inline]
pub fn assert_fuchsia_ready_repr() {
    debug_assert!(
        ZX_OBJECT_READABLE.bits() as usize == ready_as_usize(Ready::readable()),
        "Zircon ZX_OBJECT_READABLE should have the same repr as Ready::readable()"
    );
    debug_assert!(
        ZX_OBJECT_WRITABLE.bits() as usize == ready_as_usize(Ready::writable()),
        "Zircon ZX_OBJECT_WRITABLE should have the same repr as Ready::writable()"
    );
}

/// Fuchsia specific extensions to `Ready`
///
/// Provides additional readiness event kinds that are available on Fuchsia.
///
/// Conversion traits are implemented between `Ready` and `FuchsiaReady`.
///
/// For high level documentation on polling and readiness, see [`Poll`].
///
/// [`Poll`]: struct.Poll.html
#[derive(Debug, Copy, PartialEq, Eq, Clone, PartialOrd, Ord)]
pub struct FuchsiaReady(Ready);

impl FuchsiaReady {
    /// Returns the `FuchsiaReady` as raw zircon signals.
    /// This function is just a more explicit, non-generic version of
    /// `FuchsiaReady::into`.
    #[inline]
    pub fn into_zx_signals(self) -> zx_signals_t {
        zx_signals_t::from_bits_truncate(ready_as_usize(self.0) as u32)
    }
}

impl Into<zx_signals_t> for FuchsiaReady {
    #[inline]
    fn into(self) -> zx_signals_t {
        self.into_zx_signals()
    }
}

impl From<zx_signals_t> for FuchsiaReady {
    #[inline]
    fn from(src: zx_signals_t) -> Self {
        FuchsiaReady(src.into())
    }
}

impl From<zx_signals_t> for Ready {
    #[inline]
    fn from(src: zx_signals_t) -> Self {
        ready_from_usize(src.bits() as usize)
    }
}

impl From<Ready> for FuchsiaReady {
    #[inline]
    fn from(src: Ready) -> FuchsiaReady {
        FuchsiaReady(src)
    }
}

impl From<FuchsiaReady> for Ready {
    #[inline]
    fn from(src: FuchsiaReady) -> Ready {
        src.0
    }
}

impl ops::Deref for FuchsiaReady {
    type Target = Ready;

    #[inline]
    fn deref(&self) -> &Ready {
        &self.0
    }
}

impl ops::DerefMut for FuchsiaReady {
    #[inline]
    fn deref_mut(&mut self) -> &mut Ready {
        &mut self.0
    }
}

impl ops::BitOr for FuchsiaReady {
    type Output = FuchsiaReady;

    #[inline]
    fn bitor(self, other: FuchsiaReady) -> FuchsiaReady {
        (self.0 | other.0).into()
    }
}

impl ops::BitXor for FuchsiaReady {
    type Output = FuchsiaReady;

    #[inline]
    fn bitxor(self, other: FuchsiaReady) -> FuchsiaReady {
        (self.0 ^ other.0).into()
    }
}

impl ops::BitAnd for FuchsiaReady {
    type Output = FuchsiaReady;

    #[inline]
    fn bitand(self, other: FuchsiaReady) -> FuchsiaReady {
        (self.0 & other.0).into()
    }
}

impl ops::Sub for FuchsiaReady {
    type Output = FuchsiaReady;

    #[inline]
    fn sub(self, other: FuchsiaReady) -> FuchsiaReady {
        (self.0 & !other.0).into()
    }
}

#[deprecated(since = "0.6.10", note = "removed")]
#[cfg(feature = "with-deprecated")]
#[doc(hidden)]
impl ops::Not for FuchsiaReady {
    type Output = FuchsiaReady;

    #[inline]
    fn not(self) -> FuchsiaReady {
        (!self.0).into()
    }
}

impl ops::BitOr<zx_signals_t> for FuchsiaReady {
    type Output = FuchsiaReady;

    #[inline]
    fn bitor(self, other: zx_signals_t) -> FuchsiaReady {
        self | FuchsiaReady::from(other)
    }
}

impl ops::BitXor<zx_signals_t> for FuchsiaReady {
    type Output = FuchsiaReady;

    #[inline]
    fn bitxor(self, other: zx_signals_t) -> FuchsiaReady {
        self ^ FuchsiaReady::from(other)
    }
}

impl ops::BitAnd<zx_signals_t> for FuchsiaReady {
    type Output = FuchsiaReady;

    #[inline]
    fn bitand(self, other: zx_signals_t) -> FuchsiaReady {
        self & FuchsiaReady::from(other)
    }
}

impl ops::Sub<zx_signals_t> for FuchsiaReady {
    type Output = FuchsiaReady;

    #[inline]
    fn sub(self, other: zx_signals_t) -> FuchsiaReady {
        self - FuchsiaReady::from(other)
    }
}