1#![allow(unused_macros)]
2
3#[macro_export]
6macro_rules! impl_task_api {
7 () => {
8 pub fn add_timer(&mut self, id: TimerId, timer: Timer) {
11 self.timers.insert(id, timer);
12 }
13
14 pub fn has_timer(&self, timer_id: &TimerId) -> bool {
16 self.get_timer(timer_id).is_some()
17 }
18
19 pub fn get_timer(&self, timer_id: &TimerId) -> Option<&Timer> {
21 self.timers.get(&timer_id)
22 }
23
24 pub fn delete_timer(&mut self, timer_id: &TimerId) -> Option<Timer> {
26 self.timers.remove(timer_id)
27 }
28
29 pub fn add_task(&mut self, task: Task) {
31 self.tasks.push(task);
32 }
33 };
34}
35
36#[macro_export]
38macro_rules! impl_from {
39 ($a:ident < $c:lifetime > , $b:ident:: $enum_type:ident) => {
41 impl<$c> From<$a<$c>> for $b<$c> {
42 fn from(e: $a<$c>) -> Self {
43 $b::$enum_type(e)
44 }
45 }
46 };
47
48 ($a:ident, $b:ident:: $enum_type:ident) => {
50 impl From<$a> for $b {
51 fn from(e: $a) -> Self {
52 $b::$enum_type(e)
53 }
54 }
55 };
56}
57
58#[macro_export]
60macro_rules! impl_display {
61 ($enum:ident<$lt:lifetime>, {$($variant:pat => $fmt_string:expr),+$(,)* }) => {
63
64 impl<$lt> ::core::fmt::Display for $enum<$lt> {
65 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
66 use self::$enum::*;
67 match &self {
68 $(
69 $variant => write!(f, "{}", $fmt_string),
70 )+
71 }
72 }
73 }
74
75 };
76
77 ($enum:ident, {$($variant:pat => $fmt_string:expr),+$(,)* }) => {
79
80 impl ::core::fmt::Display for $enum {
81 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
82 use self::$enum::*;
83 match &self {
84 $(
85 $variant => write!(f, "{}", $fmt_string),
86 )+
87 }
88 }
89 }
90
91 };
92}
93
94#[macro_export]
99macro_rules! impl_callback {
100 ($callback_value:ident, $callback_ty:ty) => {
102 impl ::core::fmt::Display for $callback_value {
103 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
104 write!(f, "{:?}", self)
105 }
106 }
107
108 impl ::core::fmt::Debug for $callback_value {
109 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
110 let callback = stringify!($callback_value);
111 write!(f, "{} @ 0x{:x}", callback, self.cb as usize)
112 }
113 }
114
115 impl Clone for $callback_value {
116 fn clone(&self) -> Self {
117 $callback_value {
118 cb: self.cb.clone(),
119 ctx: self.ctx.clone(),
120 }
121 }
122 }
123
124 impl ::core::hash::Hash for $callback_value {
125 fn hash<H>(&self, state: &mut H)
126 where
127 H: ::core::hash::Hasher,
128 {
129 state.write_usize(self.cb as usize);
130 }
131 }
132
133 impl PartialEq for $callback_value {
134 fn eq(&self, rhs: &Self) -> bool {
135 self.cb as usize == rhs.cb as usize
136 }
137 }
138
139 impl PartialOrd for $callback_value {
140 fn partial_cmp(&self, other: &Self) -> Option<::core::cmp::Ordering> {
141 Some((self.cb as usize).cmp(&(other.cb as usize)))
142 }
143 }
144
145 impl Ord for $callback_value {
146 fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
147 (self.cb as usize).cmp(&(other.cb as usize))
148 }
149 }
150
151 impl Eq for $callback_value {}
152
153 impl From<$callback_ty> for $callback_value {
156 fn from(cb: $callback_ty) -> Self {
157 $callback_value {
158 cb,
159 ctx: $crate::refany::OptionRefAny::None,
160 }
161 }
162 }
163 };
164}
165
166#[macro_export]
171macro_rules! impl_callback_simple {
172 ($callback_value:ident) => {
173 impl ::core::fmt::Display for $callback_value {
174 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
175 write!(f, "{:?}", self)
176 }
177 }
178
179 impl ::core::fmt::Debug for $callback_value {
180 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
181 let callback = stringify!($callback_value);
182 write!(f, "{} @ 0x{:x}", callback, self.cb as usize)
183 }
184 }
185
186 impl Clone for $callback_value {
187 fn clone(&self) -> Self {
188 $callback_value {
189 cb: self.cb.clone(),
190 }
191 }
192 }
193
194 impl ::core::hash::Hash for $callback_value {
195 fn hash<H>(&self, state: &mut H)
196 where
197 H: ::core::hash::Hasher,
198 {
199 state.write_usize(self.cb as usize);
200 }
201 }
202
203 impl PartialEq for $callback_value {
204 fn eq(&self, rhs: &Self) -> bool {
205 self.cb as usize == rhs.cb as usize
206 }
207 }
208
209 impl PartialOrd for $callback_value {
210 fn partial_cmp(&self, other: &Self) -> Option<::core::cmp::Ordering> {
211 Some((self.cb as usize).cmp(&(other.cb as usize)))
212 }
213 }
214
215 impl Ord for $callback_value {
216 fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
217 (self.cb as usize).cmp(&(other.cb as usize))
218 }
219 }
220
221 impl Eq for $callback_value {}
222
223 impl Copy for $callback_value {}
224 };
225}
226
227#[allow(unused_macros)]
228macro_rules! impl_get_gl_context {
229 () => {
230 pub fn get_gl_context(&self) -> OptionGlContextPtr {
232 Some(self.gl_context.clone())
233 }
234 };
235}