From 5412767f466861a9b0ad08b3a65744c3f3b17e09 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sun, 17 Sep 2017 17:30:21 +0200 Subject: Introduce a task! macro and use it for internal pause steps --- components/script/task.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'components/script/task.rs') diff --git a/components/script/task.rs b/components/script/task.rs index 55c8f37aca4..35f202480ca 100644 --- a/components/script/task.rs +++ b/components/script/task.rs @@ -9,6 +9,26 @@ use std::intrinsics; use std::sync::Arc; use std::sync::atomic::{AtomicBool, Ordering}; +macro_rules! task { + ($name:ident: move || $body:tt) => {{ + #[allow(non_camel_case_types)] + struct $name(F); + impl ::task::Task for $name + where + F: ::std::ops::FnOnce(), + { + fn name(&self) -> &'static str { + stringify!($name) + } + + fn run(self: Box) { + (self.0)(); + } + } + $name(move || $body) + }}; +} + /// A task that can be run. The name method is for profiling purposes. pub trait Task { #[allow(unsafe_code)] -- cgit v1.2.3