Skip to content

Instantly share code, notes, and snippets.

@huonw
Created August 6, 2013 23:45

Revisions

  1. huonw created this gist Aug 6, 2013.
    25 changes: 25 additions & 0 deletions desugared.rs
    Original 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)
    }
    11 changes: 11 additions & 0 deletions sm.rs
    Original 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;
    }
    }
    }