Created
August 6, 2013 23:45
Revisions
-
huonw created this gist
Aug 6, 2013 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ enum StrangeCountIterator { priv A(int), priv B(int) } impl Iterator<int> for StrangeCountIterator { fn next(&mut self) -> Option<int> { match *self { A(mut i) => { i += 1; *self = B(i) return Some(i); } B(mut i) => { if i % 2 == 0 { i += 2; *self = A(i); return Some(i); } goto_keyword_here A(i); } } } } fn strange_count() -> StrangeCountIterator { A(0) } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ yield fn strange_count() -> int { let mut i = 0; loop { i += 1; yield i; if i % 2 == 0 { i += 2; yield i; } } }