Debian Codegraph @

third_party/rust/cubeb-pulse/src/backend/cork_state.rs

raw
1 // Copyright © 2017-2018 Mozilla Foundation
2 //
3 // This program is made available under an ISC-style license. See the
4 // accompanying file LICENSE for details.
5
6 use std::ops;
7
8 #[repr(C)]
9 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10 pub struct CorkState(u32);
11
12 const UNCORK: u32 = 0b00;
13 const CORK: u32 = 0b01;
14 const NOTIFY: u32 = 0b10;
15 const ALL: u32 = 0b11;
16
17 impl CorkState {
18 #[inline]
19 pub fn uncork() -> Self {
20 CorkState(UNCORK)
21 }
22 #[inline]
23 pub fn cork() -> Self {
24 CorkState(CORK)
25 }
26 #[inline]
27 pub fn notify() -> Self {
28 CorkState(NOTIFY)
29 }
30
31 #[inline]
32 pub fn is_cork(&self) -> bool {
33 self.contains(CorkState::cork())
34 }
35 #[inline]
36 pub fn is_notify(&self) -> bool {
37 self.contains(CorkState::notify())
38 }
39
40 #[inline]
41 pub fn contains(&self, other: Self) -> bool {
42 (*self & other) == other
43 }
44 }
45
46 impl ops::BitOr for CorkState {
47 type Output = CorkState;
48
49 #[inline]
50 fn bitor(self, other: Self) -> Self {
51 CorkState(self.0 | other.0)
52 }
53 }
54
55 impl ops::BitXor for CorkState {
56 type Output = CorkState;
57
58 #[inline]
59 fn bitxor(self, other: Self) -> Self {
60 CorkState(self.0 ^ other.0)
61 }
62 }
63
64 impl ops::BitAnd for CorkState {
65 type Output = CorkState;
66
67 #[inline]
68 fn bitand(self, other: Self) -> Self {
69 CorkState(self.0 & other.0)
70 }
71 }
72
73 impl ops::Sub for CorkState {
74 type Output = CorkState;
75
76 #[inline]
77 fn sub(self, other: Self) -> Self {
78 CorkState(self.0 & !other.0)
79 }
80 }
81
82 impl ops::Not for CorkState {
83 type Output = CorkState;
84
85 #[inline]
86 fn not(self) -> Self {
87 CorkState(!self.0 & ALL)
88 }
89 }