Skip to content

Commit 31d302f

Browse files
Update README.md
1 parent e95d531 commit 31d302f

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ enum GameError {
1010
IO { e: IOError },
1111
Alloc { e: AllocError },
1212
RandomFailed { e: RandomNumberError },
13-
ParseFailed { e: ParsingFailedError },
13+
ParseFailed { e: ParseFailedError },
1414
Game { msg: String }
1515
}
1616

@@ -22,22 +22,22 @@ struct GuessGame {
2222
target: i32,
2323
attempts: i32,
2424
} {
25-
fn play_game(&mut this): GameError!void {
25+
fn play_game(&mut this): GameError!ParseFailedError!IOError!void {
2626
for _ in 0..5 {
27-
try std.out.print("Enter your guess: ") as { e -> GameError.IO { e } }
28-
input := try std.io.read() as { e -> GameError.IO { e } }
29-
guess := try input.parse<i32>() as { e -> GameError.ParseFailed { e } }
27+
try std.out.print("Enter your guess: ")
28+
input := try std.io.read()
29+
guess := try input.parse<i32>()
3030
match guess {
3131
g if g == this.target => {
32-
try std.out.println("Correct! You win!") as { e -> GameError.IO { e } }
32+
try std.out.println("Correct! You win!")
3333
return
3434
}
35-
g if g < this.target => try std.out.println("Too low!") as { e -> GameError.IO { e } },
36-
g if g > this.target => try std.out.println("Too high!") as { e -> GameError.IO { e } },
35+
g if g < this.target => try std.out.println("Too low!"),
36+
g if g > this.target => try std.out.println("Too high!"),
3737
}
3838
this.attempts += 1
3939
}
40-
try std.out.println("Out of attempts! Game over.") as { e -> GameError.IO { e } }
40+
try std.out.println("Out of attempts! Game over.")
4141
return GameError.Game("Out of attempts!");
4242
}
4343
}
@@ -52,13 +52,13 @@ fn random_number(min: i32, max: i32): RandomNumberError!i32 {
5252
return min + (try std.random.int() % (max - min + 1))
5353
}
5454

55-
fn main(): GameError!void {
56-
let mut game: Box<GuessGame> = Box.new(GuessGame { target: try random_number(1, 10) as { e -> GameError.RandomFailed { e } }, attempts: 0 });
55+
fn main(): GameError!RandomNumberError!IOError!ParseFailedError!void {
56+
let mut game: Box<GuessGame> = Box.new(GuessGame { target: try random_number(1, 10), attempts: 0 });
5757

58-
try game.print() as { e -> GameError.IO { e } }
58+
try game.print()
5959
try *game.play_game()
6060

61-
try std.out.println("Thanks for playing!") as { e -> GameError.IO { e } }
61+
try std.out.println("Thanks for playing!")
6262

6363
// auto drop game, no borrow checking, its CTRC for the main logic and separation logic theory
6464
}

0 commit comments

Comments
 (0)