Skip to content

Commit a063755

Browse files
author
Charlie Somerville
committedApr 20, 2014
use a proper loop and iterator because why not
1 parent e66f60e commit a063755

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed
 

‎main.rs

+24-7
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,37 @@ enum Color {
2020
White = 15,
2121
}
2222

23-
fn range(lo: uint, hi: uint, it: |uint| -> ()) {
24-
let mut iter = lo;
25-
while iter < hi {
26-
it(iter);
27-
iter += 1;
23+
enum Option<T> {
24+
None,
25+
Some(T)
26+
}
27+
28+
struct IntRange {
29+
cur: int,
30+
max: int
31+
}
32+
33+
impl IntRange {
34+
fn next(&mut self) -> Option<int> {
35+
if self.cur < self.max {
36+
self.cur += 1;
37+
Some(self.cur - 1)
38+
} else {
39+
None
40+
}
2841
}
2942
}
3043

44+
fn range(lo: int, hi: int) -> IntRange {
45+
IntRange { cur: lo, max: hi }
46+
}
47+
3148
fn clear_screen(background: Color) {
32-
range(0, 80*25, |i| {
49+
for i in range(0, 80 * 25) {
3350
unsafe {
3451
*((0xb8000 + i * 2) as *mut u16) = (background as u16) << 12;
3552
}
36-
});
53+
}
3754
}
3855

3956
#[no_mangle]

0 commit comments

Comments
 (0)