Skip to content

Commit

Permalink
task_state: Generate the list of task types
Browse files Browse the repository at this point in the history
Also fix warnings.
  • Loading branch information
kmcallister committed Oct 24, 2014
1 parent 4923448 commit 4dee8ec
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions components/util/task_state.rs
Expand Up @@ -27,29 +27,29 @@ bitflags! {
}
}

// Exactly one of these should be set.
static task_types: &'static [TaskState]
= &[Script, Layout, Render];

macro_rules! predicates ( ( $( $f:ident = $c:ident ; )* ) => (
macro_rules! task_types ( ( $( $fun:ident = $flag:ident ; )* ) => (
impl TaskState {
$(
pub fn $f(self) -> bool {
self.contains($c)
pub fn $fun(self) -> bool {
self.contains($flag)
}
)*
}

#[cfg(not(ndebug))]
static TYPES: &'static [TaskState]
= &[ $( $flag ),* ];
))

predicates! {
task_types! {
is_script = Script;
is_layout = Layout;
is_render = Render;
}

#[cfg(not(ndebug))]
mod imp {
use super::{TaskState, task_types};
use super::{TaskState, TYPES};

local_data_key!(STATE: TaskState)

Expand All @@ -68,7 +68,7 @@ mod imp {
};

// Exactly one of the task type flags should be set.
assert_eq!(1, task_types.iter().filter(|&&ty| state.contains(ty)).count());
assert_eq!(1, TYPES.iter().filter(|&&ty| state.contains(ty)).count());
state
}

Expand Down

0 comments on commit 4dee8ec

Please sign in to comment.