Created
August 16, 2018 18:31
-
-
Save Pazzaz/abf434f9bae190912d29bb1e35dbde51 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro_rules! custom_loop { | |
(for $i:ident in $e:expr; $for_block:block between $between_block:block) => { | |
{ | |
let mut iter = IntoIterator::into_iter($e); | |
let a = iter.next(); | |
if a.is_some() { | |
let mut $i = a.unwrap(); | |
loop { | |
$for_block | |
$i = match iter.next() { | |
Some(x) => { | |
$between_block | |
x | |
} | |
None => { | |
break | |
} | |
} | |
} | |
} | |
} | |
}; | |
(for $i:ident in $e:expr; $for_block:block between $between_block:block then $then_block:block else $else_block:block) => { | |
{ | |
let mut _normal = true; | |
let mut iter = IntoIterator::into_iter($e); | |
let a = iter.next(); | |
if a.is_some() { | |
_normal = false; | |
let mut $i = a.unwrap(); | |
loop { | |
$for_block | |
$i = match iter.next() { | |
Some(x) => { | |
$between_block | |
x | |
} | |
None => { | |
_normal = true; | |
break | |
} | |
} | |
} | |
} | |
if _normal { | |
$then_block | |
} else { | |
$else_block | |
} | |
} | |
}; | |
(for $i:ident in $e:expr; $for_block:block between $between_block:block then $then_block:block) => { | |
{ | |
let mut _normal = true; | |
let mut iter = IntoIterator::into_iter($e); | |
let a = iter.next(); | |
if a.is_some() { | |
_normal = false; | |
let mut $i = a.unwrap(); | |
loop { | |
$for_block | |
$i = match iter.next() { | |
Some(x) => { | |
$between_block | |
x | |
} | |
None => { | |
_normal = true; | |
break | |
} | |
} | |
} | |
} | |
if _normal { | |
$then_block | |
} | |
} | |
}; | |
(for $i:ident in $e:expr; $for_block:block between $between_block:block else $else_block:block) => { | |
{ | |
let mut _normal = true; | |
let mut iter = IntoIterator::into_iter($e); | |
let a = iter.next(); | |
if a.is_some() { | |
_normal = false; | |
let mut $i = a.unwrap(); | |
loop { | |
$for_block | |
$i = match iter.next() { | |
Some(x) => { | |
$between_block | |
x | |
} | |
None => { | |
_normal = true; | |
break | |
} | |
} | |
} | |
} | |
if !_normal { | |
$else_block | |
} | |
} | |
}; | |
(for $i:ident in $e:expr; $for_block:block then $then_block:block else $else_block:block) => { | |
{ | |
let mut _normal = true; | |
let mut iter = IntoIterator::into_iter($e); | |
let a = iter.next(); | |
if a.is_some() { | |
_normal = false; | |
let mut $i = a.unwrap(); | |
loop { | |
$for_block | |
$i = match iter.next() { | |
Some(x) => {x} | |
None => { | |
_normal = true; | |
break | |
} | |
} | |
} | |
} | |
if _normal { | |
$then_block | |
} else { | |
$else_block | |
} | |
} | |
}; | |
(for $i:ident in $e:expr; $for_block:block then $then_block:block) => { | |
{ | |
let mut _normal = true; | |
let mut iter = IntoIterator::into_iter($e); | |
let a = iter.next(); | |
if a.is_some() { | |
_normal = false; | |
let mut $i = a.unwrap(); | |
loop { | |
$for_block | |
$i = match iter.next() { | |
Some(x) => {x} | |
None => { | |
_normal = true; | |
break | |
} | |
} | |
} | |
} | |
if _normal { | |
$then_block | |
} | |
} | |
}; | |
(for $i:ident in $e:expr; $for_block:block else $else_block:block) => { | |
{ | |
let mut _normal = true; | |
let mut iter = IntoIterator::into_iter($e); | |
let a = iter.next(); | |
if a.is_some() { | |
_normal = false; | |
let mut $i = a.unwrap(); | |
loop { | |
$for_block | |
$i = match iter.next() { | |
Some(x) => {x} | |
None => { | |
_normal = true; | |
break | |
} | |
} | |
} | |
} | |
if !_normal { | |
$else_block | |
} | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment