aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/macros/macros.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/macros/macros.rs')
-rw-r--r--src/components/macros/macros.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/components/macros/macros.rs b/src/components/macros/macros.rs
new file mode 100644
index 00000000000..4ae1923d1f3
--- /dev/null
+++ b/src/components/macros/macros.rs
@@ -0,0 +1,32 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#[crate_id = "github.com/mozilla/servo#macros:0.1"];
+#[crate_type = "lib"];
+
+#[feature(macro_rules)];
+
+// Spawn a task, capturing the listed variables in a way that avoids the
+// move-from-closure error. This is sugar around the function spawn_with,
+// taking care of building a tuple and a lambda.
+
+#[macro_export]
+macro_rules! bitfield(
+ ($bitfieldname:ident, $getter:ident, $setter:ident, $value:expr) => (
+ impl $bitfieldname {
+ #[inline]
+ pub fn $getter(self) -> bool {
+ let $bitfieldname(this) = self;
+ (this & $value) != 0
+ }
+
+ #[inline]
+ pub fn $setter(&mut self, value: bool) {
+ let $bitfieldname(this) = *self;
+ *self = $bitfieldname((this & !$value) | (if value { $value } else { 0 }))
+ }
+ }
+ )
+)
+