| 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