Browse Source

Handle mut declarations accordingly

Getty Ritter 4 years ago
parent
commit
b18fe170eb
1 changed files with 38 additions and 19 deletions
  1. 38 19
      src/lib.rs

+ 38 - 19
src/lib.rs

@@ -17,7 +17,7 @@ macro_rules! system {
         impl<'a> specs::System<'a> for $name {
             type SystemData = args_to_systemdata!($pat);
             fn run(&mut self, args_to_pat!($pat): Self::SystemData) {
-                for args_to_pat!($pat) in (args_to_join!($pat)).join() {
+                for args_to_pat!($pat) in args_to_join!($pat).join() {
                     $block
                 }
             }
@@ -26,32 +26,51 @@ macro_rules! system {
 }
 
 macro_rules! args_to_systemdata {
-    ( ( $( $name:ident : $ty: ty ),* ) ) => {
-        ( $( specs::WriteStorage<'a, $ty> ),* )
-    }
+    ( ( $name:ident : $ty:ty ) ) => {
+        ( specs::ReadStorage<'a, $ty> ,)
+    };
+    ( ( mut $name:ident : $ty:ty ) ) => {
+        ( specs::WriteStorage<'a, $ty> ,)
+    };
+    ( ( $name:ident : $ty:ty , $($tok:tt)* ) ) => {
+        ( specs::ReadStorage<'a, $ty>, args_to_systemdata!( ( $( $tok )* ) ) )
+    };
+    ( ( mut $name:ident : $ty:ty , $( $tok:tt )* ) ) => {
+        ( specs::WriteStorage<'a, $ty>, args_to_systemdata!( ( $( $tok )* ) ) )
+    };
 }
 
 macro_rules! args_to_pat {
-    ( ( $( $name:ident : $ty: ty ),* ) ) => {
-        ( $( mut $name ),* )
-    }
+    ( ( $name:ident : $ty:ty ) ) => {
+        ( $name ,)
+    };
+    ( ( mut $name:ident : $ty:ty ) ) => {
+        ( mut $name ,)
+    };
+    ( ( $name:ident : $ty:ty , $($tok:tt)* ) ) => {
+        ( $name, args_to_pat!( ( $($tok)* ) ) )
+    };
+    ( ( $name:ident : $ty:ty , $($tok:tt)* ) ) => {
+        ( mut $name, args_to_pat!( ( $($tok)* ) ) )
+    };
 }
 
 macro_rules! args_to_join {
-    ( ( $( $name:ident : $ty: ty ),* ) ) => {
-        ( $( &mut $name ),* )
-    }
+    ( ( $name:ident : $ty:ty ) ) => {
+        ( & $name ,)
+    };
+    ( ( mut $name:ident : $ty:ty ) ) => {
+        ( &mut $name ,)
+    };
+    ( ( $name:ident : $ty:ty , $($tok:tt)* ) ) => {
+        ( & $name, args_to_join!( ( $($tok)* ) ) )
+    };
+    ( ( $name:ident : $ty:ty , $($tok:tt)* ) ) => {
+        ( &mut $name, args_to_join!( ( $($tok)* ) ) )
+    };
 }
 
-system!{ Foo (_x: Mov, y: Pos) => {
+system!{ Foo (_x: Mov, mut y: Pos) => {
     y.x += 1;
 }
 }
-
-#[cfg(test)]
-mod tests {
-    #[test]
-    fn it_works() {
-        assert_eq!(2 + 2, 4);
-    }
-}