aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/script/macros.rs
blob: 0ebdd7c6b7e617a2215117dc3d089712cab4b3da (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/* 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/. */

#[macro_escape];

macro_rules! bitfield(
    ($bitfieldname:ident, $getter:ident, $setter:ident, $value:expr) => (
        impl $bitfieldname {
            #[inline]
            pub fn $getter(self) -> bool {
                let $bitfieldname(s) = self;
                (s & $value) != 0
            }

            #[inline]
            pub fn $setter(&mut self, value: bool) {
                let $bitfieldname(s) = *self;
                *self = $bitfieldname((s & !$value) | (if value { $value } else { 0 }))
            }
        }
    )
)