mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Move common macros into a new crate (fixes #1882)
This commit is contained in:
parent
8317122068
commit
79ca9b6eb0
8 changed files with 30 additions and 67 deletions
32
src/components/macros/macros.rs
Normal file
32
src/components/macros/macros.rs
Normal file
|
@ -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 }))
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue